1. 程式人生 > >jq實現展開全部內容,收起全部內容

jq實現展開全部內容,收起全部內容

false pre console log subst ext height con 內容

1.內容超出就隱藏一部分。

效果

技術分享

2.實現代碼:

js部分涉及到多個

var contents=[];
var maxheight=150;
for (var i=0;i< Allbox.find(‘.neirong_nr‘).length;i++){
contents.push(Allbox.find(‘.neirong_nr‘).eq(i).html())
};
console.log(contents)
var hide = function (){
Allbox.find(‘.neirong_nr‘).each(function(){
if($(this).text().length>maxheight){
$(this).text($(this).text().substring(0,maxheight));
$(this).html($(this).html()+‘...‘);
$(this).parent().find(‘.zk_kuanwen‘).html("查看更多");
} else {
$(this).parent().find(‘.zk_kuanwen‘).hide();
}
});
};
hide();
Allbox.on(‘click‘, ‘.zk_kuanwen‘, function () {
var index=$(this).parent().parent().index();
// console.log()
if($(this).parent().find(‘.neirong_nr‘).html().length<contents[index].length){
console.log( contents[index])
$(this).parent().find(‘.neirong_nr‘).html(contents[index]);
$(this).html("收起文章");
more = false;
}else{
hide();
}

});

jq實現展開全部內容,收起全部內容