0

我在下面有这段代码:

$("button").click(function(){
    $("button").off('click');  //detach click for the button below
}

然后在<body>标签中我在下面有这个按钮

<button>PLAY ANIMATION</button>

所以问题是我在哪里可以把这段代码放在下面?

$("button").bind('click'); // In other words I want to 
//reattach the click event that I just disabled at some later point
4

3 回答 3

2

工作演示 http://jsfiddle.net/2NNGv/1/

Also you can do .is(":animated") check!

jQuery ajax, wait until beforeSend animation finishes

Hope it fits the cause :) and gives you idea!

Sample code

$("button").click(function() {

    $(this).prop('disabled', 'disabled');

    $('div').animate({
        marginLeft: "-200",
        marginTop: "-200",
        width: "400",
        height: "400"
        // Comment the line below to see difference
        ,
        opacity: 0.5
    }, 2000).animate({
        marginLeft: -150,
        marginTop: -150,
        width: 300,
        height: 300
        // Comment the line below to see difference
        ,
        opacity: 1
    }, 2000).show(function() {
        $("button").removeAttr('disabled');
    });

});​
于 2012-10-12T03:58:54.043 回答
1

用于.promise()等待动画完成,稍后附加点击事件。

看这里的例子:http: //jsfiddle.net/RASG/gkveX/

返回一个 Promise 对象以观察绑定到集合的特定类型的所有操作(无论是否排队)都已完成。

此处的文档:http: //api.jquery.com/promise/

于 2012-10-12T03:54:20.183 回答
0

您是否尝试过绑定和取消绑定?

$('#foo').bind('click', function() {
  alert('The quick brown fox jumps over the lazy dog.');
});

// will NOT work
$('#foo').unbind('click', function() {
  alert('The quick brown fox jumps over the lazy dog.');
});

这是来源http://api.jquery.com/unbind/

您可以绑定按钮,然后在动画期间取消绑定,然后再次绑定以启用点击事件。

于 2012-10-12T03:50:17.737 回答