我正在尝试在被单击的项目下直接添加一个全宽项目。我尝试了两种方法(在这里小提琴)。
这是可能吗?
我尝试的第一种方法是在单击项目后直接插入新项目。如果单击的项目不是该行的最后一个项目,这会在单击的项目之后产生空白。
// First try (looks at DOM)
if (currentPosition.y === nextPosition.y) {
insertStudentContent($puff.next());
} else {
$puff.after($studentContent);
$container.isotope('reloadItems').isotope({ sortBy: 'number' });
}
第二种方法是直接在单击项的行的最后一项之后插入该项。这种方法也不是万无一失的。有时项目会在被点击的项目和被添加的项目之间出现。
$container.find('.puff').each(function (index) {
// is the item (.puff) on the same row as the one being clicked?
if ($(this).data('isotope-item-position').y === currentPosition.y) {
// The last item on the row of the clicked item will be $puff
$puff = $(this);
}
});
$puff.after($studentContent);
$container.isotope('reloadItems').isotope({ sortBy: 'number' });