Jquery mousedown button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jezternz
    New Member
    • Jan 2008
    • 145

    Jquery mousedown button

    So I want to create a button, that changes its background image when the user presses down on it. My button is a division. Now I could simply use mousedown() and mouseup(), however there are many problems that can arise from this. For example a user could push the mouse down then move the mouse off the button. The user could also press alt-tab or something after mousing down. Either of these events would cause the button to stay pressed down even though the user has mouseup'ed. I could find a bunch of ways to overcome this stuff, however I was rather hoping Jquery may already have the functionality there. Here is my simple code:
    Code:
    $("#loginButton")
        .mousedown(function(){$(this).addClass("menuButtonDown")})
        .mouseup(function(){$(this).removeClass("menuButtonDown")});
    (where #login is the button)

    Cheers, J
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    You might want to ask the jQuery developers to add the feature. They seem to be good hearted folks.

    In the meanwhile, try trapping mouseup and blurr to restore the base image. Also, focus has to handle entry with the mouse already down. It shouldn't be too difficult, I think.

    Comment

    • Jezternz
      New Member
      • Jan 2008
      • 145

      #3
      Okay, Cheers, will give that a go!

      Comment

      Working...