views:

53

answers:

3
+3  Q: 

What mouse event?

Ive noticed that if i mouse-down on a button, move my pointer from the button area, then return to it without releasing the button it still remembers that i have 'mouse-downed' on the button.

Im trying to set button styles appropriatly, 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=''}
+1  A: 

mousedown even should do the trick:

$("#button_id").mousedown(function(){
    $(this).css('color', '#00ff00');
});
Sarfraz
well mousedown - > turn button green, then followed with mouseout-> turn button red, then when i re-enter the button it will still be red when it needs to be green.
maxp
+2  A: 

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

Pointy
A: 

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

D_N
<= IE7 dont work.
maxp
Because they can't tell input types? You could certainly use jQuery for that, or put in class names yourself. The jQuery would be: $("input[type='whatever']").addClass("whatever");
D_N
Also, from the spec: "CSS 2.1 does not define if the parent of an element that is ':active' or ':hover' is also in that state.".
Pointy
@DN no the problem is that IE before IE7 didn't understand the :hover pseudo-class on any elements other than `<a>` tags.
Pointy
Oh, oh, right. Brain malfunction. Thanks.
D_N