Hi David,

You can combine events with a space in the first argument of .bind(): .bind('type1 type2 type3', function(event) { /*do something*/}); Pass the event object into the anonymous function and then determine which event was triggered with event.type. Here is an example:

$('a#cursor')
       .css({cursor: 'url(hand.cur), default'})
       .click(function() {
           return false;
       })
       .bind('mousedown mouseup mouseout', function(event) {
var myCursor = (event.type == 'mousedown') ? 'url(grab.cur), default' : 'url(hand.cur), default';
        $(this).css({cursor: myCursor});
       });

Hope that helps.


--Karl

____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com




On Sep 25, 2009, at 1:48 AM, David .Wu wrote:


event mousedown and mouseup and mouseout actually do the same thing,
how to combine it?

$('a#cursor')
       .css({cursor: 'url(hand.cur), default'})
       .click(function() {
           return false;
       })
       .mousedown(function() {
           $(this).css({cursor: 'url(grab.cur), default'});
       })
       .mouseup(function() {
           $(this).css({cursor: 'url(hand.cur), default'});
       })
       .mouseout(function() {
           $(this).css({cursor: 'url(hand.cur), default'});
       });

Reply via email to