...

View Full Version : "If" for a hover situation ?



renzocj
03-26-2012, 06:50 AM
Is it possible to built a conditional for a hover situation ? for example I wanto to do something only if the mouse is still over a DIV.



Something like this:

if (oObject.hover=true) {
do something;
}



How can I tell Javascript to check situations for Hovers on things ?

Dormilich
03-26-2012, 07:59 AM
afaik, there is nothing as simple as that, but you should be able to get the mouse position and determine from that, whether you’re in the <div>. another possibility were to trigger an event, so that you could get the targetElement (which has to be a descendent element for your <div>).

depending on your case it could even be enough to use CSS’ :hover pseudo-class

Mishu
03-26-2012, 01:08 PM
How can I tell Javascript to check situations for Hovers on things ?

You could use the onmouseover and onmouseout events. When the user hovers on a div the onmouseover code is triggered. When the user moves off the div the onmouseout code is triggered. You can use setTimeout or setInterval yo periodically check if the onmouseout event has been triggered since the last onmouseover. This will tell you if the user is still on the div or not.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum