jQuery禁用带有淡入淡出的启用点击事件 [英] jQuery disable enable click event with fade

查看:116
本文介绍了jQuery禁用带有淡入淡出的启用点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在淡入之前禁用单击事件,并在淡出之后启用它?

how can i disable click event before fadein and enable it after fadeout?

我的js代码:

$('a').click(function(){
    // disable click
    $('div').fadeOut(400,
        function(){
            $(this)
                .css('background','yellow')
            .fadeIn(1800, function(){}
             // enable click
             );});
});

我可以使用stop()但我需要禁用/启用 请修改我的 http://jsfiddle.net/WBWrM/1/ thx

i coulda use stop() but i need disable/enable plz modify my http://jsfiddle.net/WBWrM/1/ thx

推荐答案

向该元素添加一个类,并且在该类存在时不要运行该事件.

Add a class to the element, and don't run the event when that class is there.

$('a').click(function () {
    var $this = $(this);
    if ($this.hasClass('noClick')) return;
    // disable click
    $this.addClass('noClick');
    $('div').fadeOut(400, function () {
        $(this).css('background', 'yellow').fadeIn(1800, function () {
            // enable click
            $this.removeClass('noClick');
        });
    });
});

这篇关于jQuery禁用带有淡入淡出的启用点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆