jquery.dotdotdot一个jQuery插件用于当文本内容超出容器大小时显示省略号
所有必要的js文件里面的网页头部标签。
<head> <script src="jquery.js" type="text/javascript"></script> <script src="jquery.dotdotdot.js" type="text/javascript"></script> </head>
然后你可以使用CSS和JS的方法调用它们。
Css实例方法
jquery.dotdotdot添加元素:
<div class="dot-ellipsis"> <p>Lorem Ipsum is simply dummy text.</p> </div>
添加jquery.dotdotdot与窗口大小改变时更新单元:
<div class="dot-ellipsis dot-resize-update"> <p>Lorem Ipsum is simply dummy text.</p> </div>
添加jquery.dotdotdot与预定义的元素高度:
<div class="dot-ellipsis dot-height-50"> <p>Lorem Ipsum is simply dummy text.</p> </div>
JavaScript方法
创建一个DOM元素,把一些文本和其它的HTML标记在这个“wrapper”。
html
<div id="wrapper"> <p>Lorem Ipsum is simply dummy text.</p> </div>
js
$(document).ready(function() {
$("#wrapper").dotdotdot({
// configuration goes here
});
});百分比自适应以解决网页缩小后再放大文字截取过少问题
<div class="box"> <p class="par" data-con="文字内容">文字内容 </div>
$(function(){
$(".box").dotdotdot();
$(window).resize(function(){
$(".box").each( function(index,val) {
var html = $(this).find("p").attr("data-con");
$(this).find("p").html(html);
$(this).dotdotdot();
});
});
})