我试图在400到800的滚动顶部之间改变香蕉的方向,但它不起作用,我做错了很多。
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 :(得分: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;
}
}