我試圖在使用砌體庫的元素上單擊一次。它的工作方式是,當我點擊它擴展的元素時(我添加了類以使框更大),同時頁面正在滾動到該框。問題是,當你展開盒子時,它可能會掉下一條線,這意味着調用滾動的函數會滾動到錯誤的地方。它應該做的佈局,並獲得元素的新位置,然後移動...砌體 - 滾動到佈局中單擊的元素 - 無限
我知道它幾乎工作。它正在擴展盒子並進行新的佈局,並在完成後將頁面滾動到盒子中......但它看起來有點奇怪,它首先移動所有盒子以獲得新佈局,然後停止並移動頁面。我寧願這一舉一動。這是可能的。
這裏是我的代碼:
$(document).ready(function() {
var $container = $('#container');
// initialize
var msnry = new Masonry(container, {
columnWidth: 280,
itemSelector: '.item'
});
$('.openBoks').on('click', function() {
// this is my element
var thisBox = $(this).parent().parent();
// adding the class to expand it
thisBox.addClass('opened');
// calling method to do new layout
msnry.layout();
msnry.on('layoutComplete', function(msnryInstance, laidOutItems)
{
$('html, body').animate({
scrollTop: (thisBox.offset().top-10)
}, 700);
return true;
});
});
});