Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-26-2012, 05:50 AM   PM User | #1
renzocj
New Coder

 
Join Date: Sep 2011
Location: Lima, Peru
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
renzocj is an unknown quantity at this point
"If" for a hover situation ?

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.

Code:
Something like this:

if (oObject.hover=true) {
      do something;
}
How can I tell Javascript to check situations for Hovers on things ?
renzocj is offline   Reply With Quote
Old 03-26-2012, 06:59 AM   PM User | #2
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,869
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
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
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 03-26-2012, 12:08 PM   PM User | #3
Mishu
Banned

 
Join Date: Mar 2012
Posts: 306
Thanks: 1
Thanked 28 Times in 28 Posts
Mishu can only hope to improve
Quote:
Originally Posted by renzocj View Post
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.
Mishu is offline   Reply With Quote
Reply

Bookmarks

Tags
conditional, hover

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:43 PM.


Advertisement
Log in to turn off these ads.