• Blogs (9)
    • šŸ“± 236 - 992 - 3846

      šŸ“§ jxjwilliam@gmail.com

    • Version: ā€šŸš€ 1.1.0
  • jQuery: terminate an event and apply for a new event

    Blogs20132013-05-17


    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.