Parallax Scrolling

家住魔仙堡 提交于 2019-11-28 13:06:41

This may help: http://stephband.info/jparallax/ It turns nodes into absolutely positioned layers that move in response to the mouse.

http://potentpages.com/parallax-scroll-tutorial/

Here is a tutorial that my company and I created describing how to make a webpage like you are talking about. It doesn't require any jQuery or advanced CSS.

There are numerous libraries and tutorials on how to create parallax websites. We listed some here:

http://potentpages.com/parallax-tutorials/

The relevant javascript is:

var topDiv = document.getElementById("topDiv");
var speed = 1.5;

window.onscroll = function()
{
   var yOffset = window.pageYOffset;
   topDiv.style.backgroundPosition = "0px "+ (yOffset / speed) + "px";
}

Where "topDiv" is the element that you want to move slower than the "regular scrolling speed." To make the element move slower, increase the speed variable. To make it move slower, decrease it.

There are multiple tutorials around the web regarding parallax effect. Here area two just form a simple google search for "parallax effect tutorial":

http://net.tutsplus.com/tutorials/html-css-techniques/simple-parallax-scrolling-technique/

http://richardshepherd.com/smashing/parallax/

http://stephband.info/jparallax/

window.onscroll = function(e)
{
    var val = document.body.scrollTop / your_scroll_factor;
    document.getElementById('your_background_image').style.posTop = -val;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!