2016-04-16 23 views
0

我试图改变400到800之间的滚动条之间的香蕉方向,但它不能正常工作,我在做什么错误,非常感谢。试图在视差函数中创建if语句

function parallaxbananas(){ 

var scrolltop = window.pageYOffset; // get number of pixels document has scrolled vertically 

if(scrolltop < 400) { 
banana.style.top = -scrolltop * .2 + 'px' ;// move bubble1 at 20% of scroll rate 
banana2.style.top = -scrolltop * .5 + 'px';// move bubble2 at 50% of scroll rate 
banana2.style.left = -scrolltop * .5 + 'px' ; 
know.style.top=scrolltop; 
}else if(400 < scrolltop < 800){ 
banana.style.top = scrolltop * .2 + 'px' ;// move bubble1 at 20% of scroll rate 
banana2.style.top = scrolltop * .5 + 'px';// move bubble2 at 50% of scroll rate 
banana2.style.left = scrolltop * .5 + 'px' ; 
} 

}

+0

'如果(400 '如果(400 Tushar

+0

这可能是我的ISSU的一部分,但它仍然没有从一个位置移动到另一个位置 –

回答

0

刚刚才

function parallaxbananas(){ 

var scrolltop = window.pageYOffset; // get number of pixels document has scrolled vertically 

if(scrolltop < 400) { 
banana.style.top = -scrolltop * .2 + 'px' ;// move bubble1 at 20% of scroll rate 
banana2.style.top = -scrolltop * .5 + 'px';// move bubble2 at 50% of scroll rate 
banana2.style.left = -scrolltop * .5 + 'px' ; 
know.style.top=scrolltop; 
}else if(400 < scrolltop && scrolltop < 800){ 
var scrolltop2= 400 - scrolltop; 
banana.style.top = banana.style.top --- scrolltop2 * .2 + 'px' ;// move bubble1 at 20% of scroll rate 
banana2.style.top = banana2.style.top --- scrolltop2 * .5 + 'px';// move bubble2 at 50% of scroll rate 
banana2.style.left = scrolltop2 ; 
know.style.top=scrolltop2; 
} 

}