jQuery使用插件dotdotdot.js实现段落溢出显示省略号

博客开发过程中遇到需要把多行文字溢出显示省略号,试过很多方法,感觉最好用的就是dotdotdot插件,下面介绍给大家使用。


1.先上图给大家看看效果



2.使用方法

    引入插件

    < script  src = "jquery.js"  type = "text/javascript" ></ script >

    <script src="jquery.dotdotdot.js" type="text/javascript"></script>

   插件官网下载地址: http://dotdotdot.frebsite.nl


CSS实例方法

jquery.dotdotdot添加元素:

1
2
3
< div  class = "dot-ellipsis" >
     < p >Lorem Ipsum is simply dummy text.</ p >
</ div >

添加jquery.dotdotdot与窗口大小改变时更新单元:

1
2
3
< div  class = "dot-ellipsis dot-resize-update" >
     < p >Lorem Ipsum is simply dummy text.</ p >
</ div >

添加jquery.dotdotdot与预定义的元素高度:

1
2
3
< div  class = "dot-ellipsis dot-height-50" >
     < p >Lorem Ipsum is simply dummy text.</ p >
</ div >


JavaScript方法

创建一个DOM元素,把一些文本和其它的HTML标记在这个“wrapper”。

html

1
2
3
< div  id = "wrapper" >
     < p >Lorem Ipsum is simply dummy text.</ p >
</ div >

js

1
2
3
4
5
$(document).ready( function () {
     $( "#wrapper" ).dotdotdot({
         // configuration goes here
     });
});

3.配置选项

dotdotdot插件使用可以在配置对象中传递的几个选项。
所有选项(显示默认值):
  1. $(document).ready(function() {
  2. $("#wrapper").dotdotdot({
  3. /* The text to add as ellipsis. */
  4. ellipsis : '... ',
  5.  
  6. /* How to cut off the text/html: 'word'/'letter'/'children' */
  7. wrap : 'word',
  8.  
  9. /* Wrap-option fallback to 'letter' for long words */
  10. fallbackToLetter: true,
  11.  
  12. /* jQuery-selector for the element to keep and put after the ellipsis. */
  13. after : null,
  14.  
  15. /* Whether to update the ellipsis: true/'window' */
  16. watch : false,
  17. /* Optionally set a max-height, can be a number or function.
  18. If null, the height will be measured. */
  19. height : null,
  20.  
  21. /* Deviation for the height-option. */
  22. tolerance : 0,
  23.  
  24. /* Callback function that is fired after the ellipsis is added,
  25. receives two parameters: isTruncated(boolean), orgContent(string). */
  26. callback : function( isTruncated, orgContent ) {},
  27.  
  28. lastCharacter : {
  29.  
  30. /* Remove these characters from the end of the truncated text. */
  31. remove : [ ' ', ',', ';', '.', '!', '?' ],
  32.  
  33. /* Don't add an ellipsis if this array contains
  34. the last character of the truncated text. */
  35. noEllipsis : []
  36. }
  37. });

  1. });


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值