尝试在视差函数中创建 if 语句
Trying to create a if statement in a parallax function
我正在尝试在 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' ;
}
}
刚知道
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;
}
}
我正在尝试在 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' ;
}
}
刚知道
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;
}
}