Thursday, May 9, 2024
 Popular · Latest · Hot · Upcoming
31
rated 0 times [  35] [ 4]  / answers: 1 / hits: 29128  / 11 Years ago, mon, august 19, 2013, 12:00:00

without jquery



basically what I am looking for is the ability to see if the mouse is over a div when a countdown finishes



if the user is over the div then perform action for that div



onmouseover only triggers when the mouse crosses the threshold of the div, if the mouse hasn't moved it wouldn't trigger, so that wouldn't work



I need to determine if the mouse is currently over a div at a specific point in time, if it has moved or not from the starting point



all of my hunting has only found onmousover, and nothing to see if the mouse just happens to be there to begin with



I don't have the javascript skills to determine overall coords of div, then map mouse coords and see if it fits there... which is what I believe I need to do


More From » javascript

 Answers
5

set a flag to true onmouseover and to false onmouseleave. when countdown finishes if flag is true then it is over element.



HTML



<div id=div-name>the section of the code i am working with has a countdown timer, when it reaches 0 i need to know if the mouse is over a specific box</div>
<button id=notification onclick=javascript: letsCountIt(5);>click to start countdown</button>


JS



window.ev = false;

document.getElementById('div-name').onmouseover = function () {
window.ev = true;
console.log(window.ev);
}

document.getElementById('div-name').onmouseout = function () {
window.ev = false;
console.log(window.ev);
}

window.letsCountIt = function (cdtimer) {
cdtimer--;
document.getElementById('notification').innerHTML = cdtimer;

if (cdtimer == 0) {
if (window.ev === true) {
alert('over');
} else {
alert('not over');
}
} else {
setTimeout(function(){letsCountIt(cdtimer);}, 1000);
}
}

[#76273] Saturday, August 17, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kristopher

Total Points: 58
Total Questions: 103
Total Answers: 102

Location: Netherlands
Member since Thu, Jul 1, 2021
3 Years ago
;