Blogger Information
Blog 40
fans 0
comment 1
visits 34254
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
jQuery实现文章的展开与收起的小功能
景云
Original
690 people have browsed it

jQuery实现文章的展开与收起的小功能

css

  1. #detailse {
  2. height: 350px;
  3. overflow: hidden;
  4. }

html

  1. <div id="detailse">
  2. <ol>
  3. <li>li1</li>
  4. <li>li2</li>
  5. ...
  6. <li>li49</li>
  7. <li>li50</li>
  8. </ol>
  9. </div>
  10. <p id="expand"><span>∨ 展开</span></p>
  11. <ul>
  12. <li>item1</li>
  13. <li>item2</li>
  14. <li>item3</li>
  15. <li>item4</li>
  16. ....
  17. <li>item99</li>
  18. <li>item100</li>
  19. </ul>

javascript

  1. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
  2. <script>
  3. $("#expand").on("click", function () {
  4. //根据描述的高度判断用户想收起还是展开
  5. if ($("#detailse").css("height") == "350px") {
  6. //收起时修改提示信息;设置`#detailse`的高度为自适应
  7. $(this).html("<span>∧ 收起</span>");
  8. $("#detailse").css("height", "auto");
  9. } else {
  10. //收起时修改提示信息;设置将`#detailse`的高度;视口定位到提示信息处
  11. $(this).html("<span>∨ 展开</span>");
  12. $("#detailse").css("height", "350px");
  13. location.href = "#expand";
  14. }
  15. })
  16. </script>

注:未贴图、样式简单,只为实现功能;

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!