Does anyone know (as in http://james.padolsey.com/ ) how the upper body layer is scrolling at a faster speed while the background is scrolled at a slower speed making it give an effect of depth??
Can I implement multiple layers (more then 2) scrolling at different speeds using the similar concept??
Below is the bit of code that does this. I did not write it, just looked at his source and got it.
var a = document.body,
e = document.documentElement;
$(window).unbind("scroll").scroll(function () {
a.style.backgroundPosition = "0px " + -(Math.max(e.scrollTop, a.scrollTop) / 8) + "px"
})
I didn't find the code in the source, but I recreated it reasonably:
$(window).scroll(function(e){
$('body').css('background-position',
'0 ' + parseInt($(this).scrollTop()*0.5,10) + 'px');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.