开发者

What mouse event?

开发者 https://www.devze.com 2022-12-21 06:45 出处:网络
I\'ve noticed that if I mouse-down on a button, move my pointer from the button area, then return to it without releasing th开发者_如何学Ce button it still remembers that i have \'mouse-downed\' on th

I've noticed that if I mouse-down on a button, move my pointer from the button area, then return to it without releasing th开发者_如何学Ce button it still remembers that i have 'mouse-downed' on the button.

I'm trying to set button styles appropriately, could anyone enlighten me as the correct JavaScript/jQuery event to use for this?

I would really hate to use some sort of counter for this.

EDIT: OK current hacky solution;

Global called hotbutton

   $('.thisbutton').onmouseenter{if (hotbutton='thisbutton'){drawmousedowntheme();}} 

   $('.thisbutton').onmousedown{hotbutton='thisbutton';drawmousedowntheme();}

$(document).onmouseup{hotbutton=''}


What I do is:

  • Add a style ("hot") in the mouseover handler;
  • Add another style ("active") in the mousedown handler;
  • Remove "active" in the mouseup handler;
  • Remove both "active" and "hot" in the mouseout handler

The actual important stuff I always bind to "click".


mousedown even should do the trick:

$("#button_id").mousedown(function(){
    $(this).css('color', '#00ff00');
});


Why use jQuery? Set it in CSS, and the browser will do it for you (won't it?).

0

精彩评论

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

关注公众号