我想要的是当第一个(.goccia)元素到达屏幕底部时,设置间隔功能停止。
function spostaGocce(){
var goccia = document.querySelectorAll('.goccia');
for(i = 0; i < goccia.length; i++){
goccia[i].style.top = parseInt(goccia[i].style.top ||0) + Math.round(Math.random() * 2) + 1
+ 'px';
}
}
function muoviti(){
setInterval(spostaGocce, 30);
}
document.querySelector('button').addEventListener('click', muoviti);
我试图创建一个这样的变量:
gocciaTop = goccia.getBoundingClientRect().top
然后像这样做一个“如果”:
if(gocciaTop == window.innerHeight){
document.write('done')
}
但他给了我一个错误,说“getBoundingClientRect() 不是函数”。