开发者

how to check whether a button is on hover

开发者 https://www.devze.com 2023-02-12 18:08 出处:网络
Is there any javascript property to check whether a button is on hover. This i need because when the mouse is already hovered on the button i would to perform a particular task.

Is there any javascript property to check whether a button is on hover. This i need because when the mouse is already hovered on the button i would to perform a particular task.

I can see event onMouseOver but 开发者_JS百科no property to check whether mouse is hovered or not.

Can any one please help me out on how i can proceed with this.


Try this (jQuery). It's messy but you get the idea:

http://jsfiddle.net/sRsK3/1/

<input type="text" value="test"><input type="button" value="test">

<div id="div">-</div>

with:

$(function(){
    $('*')
        .data('hovering', false)
        .mouseover(function(){$(this).data('hovering', true)})
        .mouseout(function(){$(this).data('hovering', false)});
   });

window.setInterval(function() {
    $('#div').html("Textbox currently hovered: " +
                   $('input[type="text"]').data('hovering'));
}, 100)


You could use JQuery's Hover function to handle this.


I know you didnt tag this question as jQuery. but it does offer hover as an event


onMouseOver triggers an event, you could set a variable and then read the variable state from other parts of your code. For simplicity, I'd also suggest using jQuery's "hover" event.

0

精彩评论

暂无评论...
验证码 换一张
取 消