Jquery 同位素项目在追加后重新定位问题
我正在尝试使用同位素设置Ajax后期加载。但我在加载帖子并在网格中显示它们时遇到了问题。加载的栅格项目要么添加到栅格顶部,要么不按同位素定位 更新!我刚刚注意到双击网格上的项目被正确定位。但是为什么不在第一次点击时呢Jquery 同位素项目在追加后重新定位问题,jquery,wordpress,jquery-isotope,Jquery,Wordpress,Jquery Isotope,我正在尝试使用同位素设置Ajax后期加载。但我在加载帖子并在网格中显示它们时遇到了问题。加载的栅格项目要么添加到栅格顶部,要么不按同位素定位 更新!我刚刚注意到双击网格上的项目被正确定位。但是为什么不在第一次点击时呢 <div id="filters" class="button-group"></div> <div class="grid"> <div class="grid-item"></div> <div clas
<div id="filters" class="button-group"></div>
<div class="grid">
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
</div>
load posts.js
jQuery(document).ready(function($) {
var pageNum = parseInt(rvidee_alp.startPage) + 1; // The number of the next page to load (/page/x/).
var max = parseInt(rvidee_alp.maxPages); // The maximum number of pages the current query can return.
var nextLink = rvidee_alp.nextLink; // The link of the next page of posts.
var grid = $('.grid'); // Posts container
if(pageNum <= max) {
$('.posts') // Insert the "More Posts" link.
.append('<div class="col"><a id="load-posts" href="#0">Load more</a></div>');
$('.navigation').remove(); // Remove the traditional navigation.
}
$(document).on('click', '#load-posts', function(){
if(pageNum <= max) { // Are there more posts to load?
$(this).text('Loading posts...');
$.get(nextLink, function(data){
pageNum++;
nextLink = nextLink.replace(/\/page\/[0-9]?/, '/page/'+ pageNum);
$(data).find('.grid-item').appendTo(grid);
if(pageNum <= max) {
$('#load-posts').text('Load more');
} else {
$('#load-posts').text('No more to load.');
}
});
} else {
$('#load-posts').append('.');
}
$('.grid').isotope( 'reloadItems').isotope();
return false;
});
});
jQuery(文档).ready(函数($){
var pageNum=parseInt(rvidee_alp.startPage)+1;//要加载的下一页的编号(/page/x/)。
var max=parseInt(rvidee_alp.maxPages);//当前查询可以返回的最大页数。
var nextLink=rvidee_alp.nextLink;//文章下一页的链接。
var grid=$('.grid');//Posts容器
如果(pageNum最终我发现了问题。我应该从一开始就使用insert,而不是append和reloadItems。需要更改两行:
var newItems = $(data).find('.grid-item');
$('.grid').isotope( 'insert', newItems );
var newItems = $(data).find('.grid-item');
$('.grid').isotope( 'insert', newItems );