我使用jQuery的同位素插件新聞欄目的網絡佈局的高度,顯示了與read more
每個按鈕的第一段每條新聞,一旦點擊顯示內容的其餘部分。
這裏是我的榜樣,我會解釋我遇到的問題:
的jsfiddle:http://jsfiddle.net/neal_fletcher/gXukc/4/
的jQuery:動態決定DIV
$(document).ready(function() {
var $container = $('#main-grid');
$container.imagesLoaded(function() {
$container.isotope({
itemSelector: '.grid-block, .grid-block-long',
animationEngine: 'best-available',
masonry: {
columnWidth: 5
}
});
});
});
$(document).ready(function() {
$('.grid-block-text p').hide().filter(":first-child").show();
});
$(document).ready(function() {
$('.read-more').click(function() {
$(this).hide();
$(this).nextAll('.grid-block-text')
.children('p').fadeIn('slow');
$(this).siblings('.read-less').fadeIn('slow');
$(this).parent('.grid-block')
.removeClass('grid-block')
.addClass('grid-block-long');
$('#main-grid').isotope('reLayout');
$container.isotope();
});
$('.read-less').click(function() {
$(this).hide();
$(this).nextAll('.grid-block-text')
.children("p:not(:first-child)").fadeOut('fast');
$(this).siblings('.read-more').fadeIn('slow');
$(this).parent('.grid-block-long')
.removeClass('grid-block-long')
.addClass('grid-block');
$('#main-grid').isotope('reLayout');
$container.isotope();
});
});
正如你可以在所示的例子中看到,點擊按鈕read more
加載休息的文本內容並切換div的類以允許文本適合。我這樣做的原因是我一直想的div的高度,以適應電網,即在本例中,較長的div的長度等於較短的2個,因此總是排隊。
但是,因爲這將是一個新聞欄目,我不能否定的大部分文字是怎麼去那裏,所以我試圖找出這是否可以被動態地進行。
例如grid-block
高度爲300像素,如果文字內容長度超過300像素,則會切換到630像素,依此類推。
任何建議將不勝感激!
哇,完美,正是我在後!謝謝你,非常感謝。 – user1374796
它的作品,即使沒有克隆格,這是更「優雅」對我來說http://jsfiddle.net/mattydsw/gXukc/10/ – mkutyba