如何使用jquery实现一定长度的文字/More/Less
2013-12-31 12:22
483 查看
<p class="minimize">It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text.</p> <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text.</p> <p class="minimize">It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text.</p>
css
p { padding: 0 0 20px; }
jquery
jQuery(function(){ var minimized_elements = $('p.minimize'); minimized_elements.each(function(){ var t = $(this).text(); if(t.length < 100) return; $(this).html( t.slice(0,100)+'<span>... </span><a href="#" class="more">More</a>'+ '<span style="display:none;">'+ t.slice(100,t.length)+' <a href="#" class="less">Less</a></span>' ); }); $('a.more', minimized_elements).click(function(event){ event.preventDefault(); $(this).hide().prev().hide(); $(this).next().show(); }); $('a.less', minimized_elements).click(function(event){ event.preventDefault(); $(this).parent().hide().prev().show().prev().show(); }); });
来源: Fiddle
相关文章推荐
- 使用纯CSS实现文字超过一定的长度后自动显示省略号
- 如何使用jquery实现文字上下滚动效果
- 如何使用jQuery+PHP+MySQL来实现一个在线测试项目
- Jquery中对checkbox的各种“全选”或者“取消”功能实现(特别注意1.6+的一定不能使用attr来取属性了!用prop!)
- 如何使用jQuery来处理图片坏链具体实现步骤
- 使用CSS如何实现页面两行文字两端对齐
- jquery使用CSS3实现文字动画效果插件Textillate.js
- 如何使用jquery动态加载js,css文件实现代码
- 使用Jquery+Ajax+Json如何实现分页显示附JAVA+JQuery实现异步分页
- 如何使用jquery实现全屏问题
- jquery使用CSS3实现文字动画效果插件Textillate.js
- jQuery实现 div里面的文字如何自动缩小,避免文字溢出
- 使用jquery实现文字滚动,鼠标悬停效果
- 如何使用jquery动态加载js,css文件实现代码
- 使用jquery.more.js来实现点击底部更多后, 底部加载出新的数据
- jQuery实现滚动条向下拉到一定的程度,然后这层就一直占着不管滚动条如何向下拉都不动了的效果
- jquery使用toggle时如何设置两个状态的文字,一句代码搞定
- 如何使用jQuery+PHP+MySQL来实现一个在线测试项目
- 如何使用jQuery+PHP+MySQL来实现一个在线测试项目