开发者

Bind & Unbind... how to bind again when this function finished?

开发者 https://www.devze.com 2023-03-09 13:10 出处:网络
http://jsfiddle.net/3NRsd/ var foo =$(\"div\").bind(\"click\", function() { $(\"div\").animate({\"height\" : \"500开发者_如何学Pythonpx\"}, 2000);

http://jsfiddle.net/3NRsd/

var foo =  $("div").bind("click", function() {
    $("div").animate({"height" : "500开发者_如何学Pythonpx"}, 2000);
    $("div").animate({"height" : "50px"}, 2000);
    $("div").unbind();
    });


You could do:

function handler() {
    $(this)
     .unbind()
     .animate({"height" : "500px"}, 2000);
     .animate({"height" : "50px"}, 2000, function(){
         $(this).click(handler); // <- gets called once the animation finishes
     });
}

$('div').click(handler);

DEMO


You can rebind it in a callback from the animate function:

http://jsfiddle.net/3NRsd/8/

0

精彩评论

暂无评论...
验证码 换一张
取 消