我试图确定一个元素的高度大于55.如果是这种情况,包装div应该折叠为55px,并且“Read-more”链接应该出现。
问题是,dom导航器.next()和.hide()不在我的每个函数内部工作。我得到的元素的高度是好的,我将它们记录到控制台并获得不同的值,这是可以的。但是,当我使用IF语句来隐藏要小的元素的.read-more链接时,它不起作用。
这是我的小提琴http://jsfiddle.net/eKDUe/,我完全失去了。我希望有人能帮帮忙!
readMore.prev('p').each(function(index) {
var deg = $(this).height();
console.log(deg);
if (deg < 55){
var as = $(this);
var as2 = as.next();
console.log(as2);
}
});
readMore.on('click', function(){
$this = $(this);
var current = $this.prev();
console.log(current);
if(current.height() < 55){
current.css('height', 'auto');
$this.html('Dölj');
}else{
current.css('height', '53px');
$this.html('Läs mer');
}
});
什么是'readMore'? –