最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery實現(xiàn)長文字部分顯示代碼

 更新時間:2013年05月13日 15:15:26   作者:  
在網(wǎng)頁上只有一個小區(qū)域,但是說明性的文字又很長,下面這段腳本實現(xiàn)的是長文字的部分顯示,有類似需求的朋友可以參考下哈,希望對你有所幫助

在網(wǎng)頁上只有一個小區(qū)域,但是說明性的文字又很長,下面這段腳本實現(xiàn)的是長文字的部分顯示。
當用戶點擊展開時,文字展開,合起是文字合起。

本來用jQuery自帶的toggle()就可以寫,但是我做的時候 toggle一直不work,所以就用了click + 標志位來做的

復制代碼 代碼如下:

<script language="javascript" src="jquery.js"></script>
<script language="javascript">
var cur_status = "less";
$.extend({
show_more_init:function(){
//alert("show_more_init!");
var charNumbers=$(".content").html().length;//總字數(shù)
var limit=100;//顯示字數(shù)
if(charNumbers>limit)
{
var orgText=$(".content").html();//原始文本
var orgHeight=$(".content").height();//原始高度
var showText=orgText.substring(0,limit);//最終顯示的文本
$(".content").html(showText);
var contentHeight=$(".content").height();//截取內容后的高度
$(".switch").click(
function() {
if(cur_status == "less"){
$(".content").height(contentHeight).html(orgText).animate({ height:orgHeight}, { duration: "slow" });
$(this).html("合起");
cur_status = "more";
}else{
$(".content").height(orgHeight).html(showText).animate({ height:contentHeight}, { duration: "fast" });
$(this).html("展開");
cur_status = "less";
}
}
);
}
else
{
$(".switch").hide();
}
}
});
$(document).ready(function(){
$.show_more_init();
});
</script>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<style>
#limittext{
width:640px;
height:auto;
position:relative;
background-color:#ccc;
color:black;
}
.switch{
font-size:12px;
text-align:center;
cursor:pointer;
font-family:Verdana;
font-weight:800;
position:absolute;
bottom:0;
width:100%;
/*background:url(more-bg.png) repeat-x bottom;*/
height:40px;
line-height:80px;
}
</style>
</head>
<body>
<div id="limittext" >
<div class="content" style="padding-bottom:15px;">
這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字,這是很長的一段文字
</div>
<div class="switch">展開</div>
</div>
</body>
</html>

相關文章

最新評論

深州市| 伽师县| 柞水县| 阿图什市| 东兰县| 湛江市| 合水县| 梁山县| 体育| 怀集县| 积石山| 左权县| 象山县| 灵丘县| 托里县| 道真| 东乡| 马关县| 平遥县| 静海县| 容城县| 江城| 安康市| 嘉义县| 桦甸市| 浪卡子县| 石河子市| 益阳市| 丰城市| 辉南县| 霍邱县| 临夏市| 海淀区| 五指山市| 湘西| 仙桃市| 舟曲县| 武邑县| 获嘉县| 甘孜县| 绵阳市|