国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

文本溢出插件jquery.dotdotdot.js使用方法詳解

2024-05-06 15:15:35
字體:
來源:轉載
供稿:網友

插件下載地址:https://github.com/FrDH/jQuery.dotdotdot

引入jQuery.js和jquery.dotdotdot.js

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

給包含文本的元素定一個寬高,當文本超過這個高度后會觸發效果

變成省略號:

<div class="box" style="width:300px;height:100px;"> 測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</div><script type="text/javascript"> $(function(){   $(".box").dotdotdot();  })  </script>

有省略號加自己定義內容:

<div class="box02" style="width:300px;height:100px;"> 測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試 <span style="color:#ff0000;"><a style="color: #F4606C">read more</a></span></div><script type="text/javascript"> $(function(){   $(".box02").dotdotdot({    after: 'a'   });  });</script>

有展開/收起 按鈕:

<div class="box03" style="width:300px;height:100px;"> 測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</div><style type="text/css">.opened{height: auto;} .toggle .close,.opened .toggle .open{display: none;} .toggle .opened,.opened .toggle .close{display: inline;} </style><script type="text/javascript"> var $dot = $('.box03'); $dot.append( ' <a class="toggle" href="#" rel="external nofollow" ><span class="open">[ + ]</span><span class="close">[ - ]</span></a>' ); function createDots() {  $dot.dotdotdot({    after: 'a.toggle'   }); } function destroyDots() {  $dot.trigger( 'destroy' ); } createDots(); $dot.on(    'click',    'a.toggle',    function() {    $dot.toggleClass( 'opened' );    if ( $dot.hasClass( 'opened' ) ) {     destroyDots();     } else {     createDots();     }    return false;    } );</script>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 灌云县| 永昌县| 无为县| 阳信县| 郎溪县| 桃园县| 兴化市| 崇礼县| 沙田区| 绥阳县| 张家界市| 耿马| 新宾| 崇文区| 从化市| 门头沟区| 荣成市| 彭阳县| 南康市| 封丘县| 汾西县| 金门县| 哈巴河县| 舟山市| 合山市| 九江市| 高台县| 呼伦贝尔市| 察隅县| 吴忠市| 当雄县| 乐至县| 汉源县| 池州市| 社会| 弥渡县| 平湖市| 昌吉市| 屏山县| 繁昌县| 靖州|