【发布时间】:2018-05-05 05:52:03
【问题描述】:
我正在尝试一个相对简单的事情..
我在 wordpress 中有一个自定义帖子类型的存档页面,我在分页中每页显示十个帖子并运行 isotope js 进行 div 打包,我使用 next_posts_link() 生成 ID 为“#next_archive_page”的链接。一切都很好,这一切都按预期工作。
现在我正在尝试添加将实现 infiniteScroll 功能的 jQuery,但我可以让这些新帖子的图像呈现的唯一方法是删除 img-fluid 的引导类来自他们(这只是 width: 100%; height: auto; )...
<div class="row grid">
<?php if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post() ?>
<div class="grid-sizer col-4">
<img class="img-fluid" src="...">
</div>
<?php endwhile; endif; wp_reset_query() ?>
</div>
<script>
window.onload = function() {
var $grid = $('.grid').isotope({
itemSelector : '.grid-item',
columnWidth : '.grid-sizer',
percentPosition : true
});
$grid.infiniteScroll({
hideNav: '.pagination',
path : '.pagination #next_archive_page',
scrollThresold: 200
});
$grid.on( 'load.infiniteScroll', function( event, response, path ) {
var $items = $( response ).find('.grid-item');
// It's the height: auto style that stops images displaying
$items.find('img').removeClass('img-fluid');
$items.imagesLoaded( function() {
$grid.append( $items );
$grid.isotope( 'insert', $items );
});
});
}
</script>
我不想删除 ing-fluid 类,因为我的响应式布局需要它...
因此,这样做的结果是它将下一个自定义帖子类型存档页面中的 .grid-item 元素附加到正确的位置,但它们都是重叠的并且大小错误。
我怎样才能让infiniteScroll 和isotope 在引导响应方面发挥出色?
【问题讨论】:
标签: jquery wordpress bootstrap-4 infinite-scroll jquery-isotope