在html中,一段文字太长。想实现初始化后只显示一部分文字,点击显示更多后,显示全部。如何实现?
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;
});
}
});