Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2011
    Location
    Lima, Peru
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    "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 ?

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,247
    Thanks
    12
    Thanked 340 Times in 336 Posts
    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
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Banned
    Join Date
    Mar 2012
    Posts
    306
    Thanks
    1
    Thanked 28 Times in 28 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •