William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

jQuery: terminate an event and apply for a new event

jQuery: terminate an event and apply for a new event: stop(true,true)

How to terminate a jQuery event immediately, and apply for a new event? It is better to use the interact function stop(true,true).
stop(true, true) is helpful to stop an running event on certain DOM element, and apply for a new event.
e.g.: stop a slideUp() event and apply a slideDown event, like this:

var mouseHandler = function (e) {
    e.preventDefault();
    e.stopPropagation();
    $.debug('<mouseHandler>, e.type=' + e.type);
    $('div#list_popup').stop(true, true).slideDown('slow');
    return false;
};  
$('div.list').one('mouseenter mouseleave', mouseHandler);

In this way, it will change slideUp() to slideDown() immediately when the ‘mouseenter’ or ‘mouseleave’ are triggered.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: