简体   繁体   English

使用javascript的无限滚动效果

[英]Infinite Scroll Effect with javascript

anyone have a clue how to make a sroll effect like this? 有谁知道如何制作这样的滚动效果? http://www.eurekasoft.com http://www.eurekasoft.com

I know the content is repeated at the end to create the illusion but i would like to know how to achieve the seemingly never end scroll. 我知道内容会在末尾重复以创建错觉,但我想知道如何实现看似永无止境的滚动。

Thanks! 谢谢!

It appears that site is using Skrollr: http://prinzhorn.github.io/skrollr/ 网站似乎正在使用Skrollr: http ://prinzhorn.github.io/skrollr/

Scroll all the way down for links to the Github and more examples. 一直滚动到Github链接以及更多示例。

Deep down, it is using the function window.scrollTo() to set the scroll position, and probably setting DOM around that area so that it looks the same as where it was scrolled from. 在最深处,它使用函数window.scrollTo()设置滚动位置,并可能在该区域周围设置DOM,以使其看起来与从其滚动的位置相同。

https://github.com/Prinzhorn/skrollr/blob/master/src/skrollr.js#L617 https://github.com/Prinzhorn/skrollr/blob/master/src/skrollr.js#L617

This works for me :) 这对我有用:)

here is the example: http://www.cancerbero.mx (only enable in Chrome and Safari) 这是示例: http : //www.cancerbero.mx (仅在Chrome和Safari中启用)

// #loop is the div ID where repetition begins

$(document).ready(function(){
            $(window).scroll(function(){
                var scroll = $(window).scrollTop();
                var limit = $('#loop').position().top;
                if(scroll >= limit){
                    window.scrollTo(0,1); // 1 to avoid conflicts
                }
                if(scroll == 0){
                  window.scrollTo(0,limit);  
                }
            });
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM