在html中,一段文字太长。想实现初始化后只显示一部分文字,点击显示更多后,显示全部。如何实现?
3条回答 默认 最新
weixin_36444515 2019-05-22 16:21关注jquery实现
$(function() {
var slideHeight = 45; // px 定义折叠的最小高度
var defHeight = $('#wrap').height();
if(defHeight >= slideHeight) {
$('#wrap').css('height', slideHeight + 'px');
$('#read-more').append('更多');
$('#read-more a').click(function() {
var curHeight = $('#wrap').height();
if(curHeight == slideHeight) {
$('#wrap').animate({
height: defHeight
}, "normal");
$('#read-more a').html('折叠');
} else {
$('#wrap').animate({
height: slideHeight
}, "normal");
$('#read-more a').html('更多');
}
return false;
});
}
});本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用 2