实现原理:当点击展开时,获取元素height: auto的高度为多少像素,由当前高度到height:auto的过渡;反之。
var m_flag = true;
var el = $(".case-detail-con"),
curHeight = el.height();
$("#casesdetail_more").click(function(){
if(m_flag){
autoHeight = el.css('height', 'auto').height();
el.height(curHeight).animate({height: autoHeight}, 500);
$(this).find("span").html("收起");
$(this).find("img").addClass('open');
m_flag = false;
}else{
autoHeight = el.css('height', 'auto').height();
el.height(autoHeight).animate({height: curHeight}, 500);
$(this).find("span").html("展开");
$(this).find("img").removeClass('open');
m_flag = true;
}
})
.case-detail-con {
margin-bottom: 25px;
font-size: 12px;
color: #666;
line-height: 20px;
height: 260px;
overflow: hidden;
}