1
我正在使用Ian Lunn的视差教程http://www.ianlunn.co.uk/demos/recreate-nikebetterworld-parallax/。我想在此基础上不仅改变背景的y位置,而且还改变滚动的x位置。这基本上会增加水平移动以及垂直移动,以便一些物体在两个方向上移动。在滚动上更改背景位置-x
有关我想要做的一个示例http://www.nikebetterworld.com/product。汽车进入的第三个场景是我试图实现的运动。
他原来的代码是:
//function that is called for every pixel the user scrolls. Determines the position of the background
/*arguments:
x = horizontal position of background
y = vertical position of the background
windowHeight = height of the viewport
pos = position of the scrollbar
adjuster = adjust the position of the background
inertia = how fast the background moves in relation to scrolling
backgroundPosition-y = original background position vertical
*/
function newPos(x, windowHeight, pos, adjuster, inertia){
return x + "% " + (-((windowHeight + pos) - adjuster) * inertia) + "px";
}
//function to be called whenever the window is scrolled or resized
function Move(){
var pos = $window.scrollTop(); //position of the scrollbar
//if the first section is in view...
if($firstBG.hasClass("inview")){
//call the newPos function and change the background position
$firstBG.css({'backgroundPosition': newPos(20, windowHeight, pos, 300, 0.1)});
sun_1.css({'backgroundPosition': newPos(10, windowHeight, pos, 4000, .1)});
deer.css({'backgroundPosition': newPos(40, windowHeight, pos, 500, .1)});
}
我敢肯定,这是非常非常错误的事,但这里是我试过。
sun_1.css({'backgroundPosition': newPos(10, windowHeight, pos, 4000, .1)}, {'background-position-x': '0% ' + parseInt(-xx/ 10) + 'px'});
有没有办法将其添加到“newPos”功能?