How to Scroll layers with multiple rate on website

那年仲夏 提交于 2019-12-06 06:29:46

问题


I found this website with an effect that I would like to replicate. To see what I am talking about go here:

http://www.rowtothepole.com/

When scrolling through the webpage you can see that the iceberg layer scrolls at a different rate as the text box on top of it. I would like to know how they are doing this.


回答1:


In their http://www.rowtothepole.com/release/includes/js/parallax.js

there are code to shift the body's background image and an outer div's background image, which are for the icebergs and for the clouds:

Event.observe(window, "scroll", function() {
    var offset = document.viewport.getScrollOffsets();

    $(document.body).setStyle({
      'backgroundPosition': 'center -' + (offset[1] / px_scroll_amt) + 'px'
    });

    if (xhr_support) {
        $("outer").setStyle({
          'backgroundPosition': 'center -' + (offset[1] / (px_scroll_amt / 3)) + 'px'
        });
    }
});


来源:https://stackoverflow.com/questions/4231979/how-to-scroll-layers-with-multiple-rate-on-website

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