Magnific popup and infinite scrolling

自作多情 提交于 2019-12-11 09:07:44

问题


I have a tumblr blog whit infine scrolling and magnific-popup to visualize the image.

When I scroll to the bottom and load new posts, magnific-popup doesn't works in the new posts loaded but only in the old.

If I try to go to "page-2" manually everything works.

Is there a way to reload magnific-popup on load posts or something similar?

Many thanks


回答1:


All you need to do is call the .magnificPopup method on the new elements when infinitescroll is loaded, this way:

$YOUR_CONTAINER.infinitescroll({
    navSelector:  ".Pagination",
    nextSelector: ".Pagination-next",
    itemSelector: ".Post"
}, function( newElements ) {
    $(newElements).magnificPopup({/*your options here*/});
});



回答2:


You can use onInit event for callback function. See more

Example code:

$('.your-class-name').infiniteScroll({
    // options
    path: '.next.page-numbers',
    append: '.post',
    history: false,
    status: '.page-load-status',
    button: '.page-load-more',
    loadOnScroll: false,
    elementScroll: true,
    hideNav: '.post-pagination',
    onInit: function() {
        this.on( 'append', function() {
            $('.your-item-class-name').magnificPopup({
                /* magnificPopup options here */
            });
        });
    }
});


来源:https://stackoverflow.com/questions/23761192/magnific-popup-and-infinite-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!