Javascript very difficult question. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 }

4th Sep 2020, 6:24 PM
Uzair Malim
Uzair Malim - avatar
4 Answers
+ 2
Make a var t = setInterval(myFunction, 3000); In myfunction, make a clearInterval myFunction(){ ... clearInterval(t); }
4th Sep 2020, 6:45 PM
Nathan Sikati
Nathan Sikati - avatar
+ 1
Divya Mohan of course, it is used in most cases
5th Sep 2020, 12:26 AM
Uzair Malim
Uzair Malim - avatar
0
I think Because your mouser curser must be on your window everytime. Mouserover event is generally used for elements not for window.
4th Sep 2020, 6:42 PM
Divya Mohan
Divya Mohan - avatar
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.
5th Sep 2020, 2:40 AM
Divya Mohan
Divya Mohan - avatar