Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

超过n行显示...并且显示【展开】/【收起】 #14

Open
milixie opened this issue Nov 12, 2019 · 0 comments
Open

超过n行显示...并且显示【展开】/【收起】 #14

milixie opened this issue Nov 12, 2019 · 0 comments

Comments

@milixie
Copy link
Owner

milixie commented Nov 12, 2019

示例

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" >
  <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1">
  <title>xxx</title>
  <style type="text/css">
    .text {
      display: -webkit-box;
      -webkit-line-clamp: 6;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }
    /*label {
      display: none;
    }
    label::after {
      content: "显示更多";
    }
    .text.truncated + label {
      display: block;
    }
    .text.truncated + label::after {
      content: "点击收起";
    }*/

    input[name="toggle"]:checked + p {
      -webkit-line-clamp: unset;
    }
    input[name="toggle"] ~ label::after {
      content: "显示更多";
    }

    input[name="toggle"]:checked ~ label::after {
      content: "收起文本";
    }

  </style>
</head>
<body>
  <div class="box">
    <input type="checkbox" name="toggle" id="toggle" style="display: none;">
    <p class="text">我我我我我我小心点的点点滴滴创建的觉得讲讲点击点击觉得就就点击点击大家就姐姐到家觉得讲讲解放军对讲机基督教家具家电姐姐到家安静司法局啊诶接发阿胶二姐我我我我我我小心点的点点滴滴创建的觉得讲讲点击点击觉得就就点击点击大家就姐姐到家觉得讲讲解放军对讲机基督教家具家电姐姐到家安静司法局啊诶接发阿胶二姐</p>
    <label for="toggle" onclick="clickHandle"></label>
  </div>
<script type="text/javascript">
  // window.onload = function() {
  //   let list = document.querySelectorAll("p");

  //   list.forEach(item => {
  //     item.classList[item.scrollHeight > item.offsetHeight ? "add" : "remove"]("truncated");
  //   });
  // }
</script>
</body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant