javascript - jQuery:无限滚动和后退按钮

标签 javascript jquery html jquery-isotope infinite-scroll

好吧,我知道这会给每个人带来问题,它也会给我带来问题。我在客户网站上使用无限滚动插件,结契约(Contract)位素插件按顺序加载他们的产品,问题是他们有 1000 种产品,任何浏览网站然后点击产品的人,当他们点击后退按钮它们将返回到顶部(或刚好在第一页的折叠上方),这会导致很多问题。

我的标记如下:

$(window).load(function () {

    var $container = $('.products-grid-wrap');

    $container.imagesLoaded(function () {
        $container.isotope({
            itemSelector: '.products-grid-block',
            filter: '*:not(.hidden), .products-grid-block',
            animationEngine: 'best-available',
            layoutMode: "perfectMasonry",
            perfectMasonry: {
              columnWidth: 280,
              rowHeight: 310
            }
        });         

        $container.infinitescroll({
            navSelector: '#page_nav', // selector for the paged navigation 
            nextSelector: '#page_nav a', // selector for the NEXT link (to page 2)
            itemSelector: '.regular-product-block, .products-grid-block', // selector for all items you'll retrieve
            pixelsFromNavToBottom: Math.round($(window).height() * 1.5),
            bufferPx: Math.round($(window).height() * 1.5),
            loading: {
                finishedMsg: 'No more products to load.',
                img: 'http://www.by-form.net/wp-content/uploads/2014/11/ajax-loader-big.gif'
            }
        },
        // call Isotope as a callback
        function (newElements) {
            var $newElems = $(newElements);
            $newElems.imagesLoaded(function () {
                $container.isotope('insert', $newElems);
                $('.products-grid-rollover-block').hide();                 
                   if(newElements.length > 0){
                       setTimeout(function () {
                            $container.infinitescroll('retrieve');
                            $('.products-grid-wrap').isotope('reLayout');
                            //$('.products-grid-wrap').isotope({
                            //sortBy: 'category',
                                //sortAscending: false });
                        }, 1000);
                   }

            });
        }); 

        setTimeout(function () {
            $container.infinitescroll('retrieve');
        }, 3000); 

    });

});

如有任何解决方案或建议,我们将不胜感激!

最佳答案

你可以试试scroll-frame .It is a bit old 可能是你的答案。这是一个链接 infinite scroll demo使用它。

scrollFrame 将劫持用户对与您传入的查询选择器匹配的元素的点击,而不是重新加载页面,它会附加一个类似模态的 iframe,它位于视口(viewport)顶部并指向元素的 href。然后它使用 HTML5 历史 API 使后退按钮按预期运行。

关于javascript - jQuery:无限滚动和后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35181903/

相关文章:

javascript - 一个页面上同一 javascript 类的两个实例引用同一实例

javascript - 类模拟中的 JS 和方法

jquery - 图形树创建

html - 带 float 的图像换行不能正常工作

html - 我可以在 Google 云端硬盘虚拟主机中使用谷歌字体吗?

javascript - 使用 Math.round 后在 JavaScript 中为 -0?什么是-0?

javascript - 如何在xcode 5.1.1中使用phonegap-1.3.0.js实现相机功能

jquery - Flatpickr - 限制可以选择的日期数量

javascript - 调整具有多种字体大小的 div 中的文本大小?

javascript - 什么会影响键盘焦点 html?