What I want is when the first (.goccia) element reach the bottom of the screen the set interval function stop.
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);
I tried to create a variable like this:
gocciaTop = goccia.getBoundingClientRect().top
and then do an 'if' like this:
if(gocciaTop == window.innerHeight){
document.write('done')
}
But he gave me an error that say that 'getBoundingClientRect() is not a function'.