How can I make it so that the following code will be executed only when the move moves using the onmousemove
event.
settimeout(function(){ confirm("Hello"); }, 3000);
I'm looking for a pure JavaScript solution only.
How can I make it so that the following code will be executed only when the move moves using the onmousemove
event.
settimeout(function(){ confirm("Hello"); }, 3000);
I'm looking for a pure JavaScript solution only.
You could handle the mousemove
event by doing something similar to what I have below:
var handler = function(e) {
console.clear();
console.log(`Mouse at: X:${e.screenX} Y:${e.screenY}`);
}
document.body.addEventListener('mousemove', function(e) {
//setTimeout(function() {
handler(e);
//}, 1000)
});
<body>
<p>Here is some text
</p>
<p>Event should fire when hovering
</p>
<p>any text in a child element of document.body
</p>
</body>
In my example I commented out the setTimeout
(which is case-sensitive, by the way) method and just log the X and Y coordinates of the mouse pointer at the time of the event. You could put whatever you want in the handler - I just didn't think that worked well for the sake of an event handling example.