+ 2
Javascript very difficult question.
This is an example. I want to execute my function only one time after 3s of mouseover and scroll event. But it is executing continuously. Is it possible? window.addEventListener("mouseover", myFunction); window.addEventListener("scroll", myFunction); setTimeout (3000, myFunction) ; myFunction () { do something }
4 odpowiedzi
+ 2
Make a
var t = setInterval(myFunction, 3000);
In myfunction, make a clearInterval
myFunction(){
...
clearInterval(t);
}
+ 1
Divya Mohan of course, it is used in most cases
0
I think
Because your mouser curser must be on your window everytime.
Mouserover event is generally used for elements not for window.
0
It may repeat many time that something bcz it consider every px of scroll as new scroll.
I have tried the 2nd one with console.log("hello world")
and repeated several time .
So above one can be possible reason.