1
$(function(){ 
    $(".square").toggle(
        function(){ $(this).animate({"width":"200px"}, 900); 
                  },

        function(){ $(this).animate({"width":"100px"}, 900); 
        } 
    ); 

    $(document).click(function() {
       $('.square').animate({ "width":"100px"}, 900);  
    });
})​

この例では、
1- ユーザーが正方形を 1 回クリックします (トグルの最初の機能が実行されます)。
2- ユーザーが背景をクリックすると、別の関数が呼び出され
ます最初のクリック。)

だから私は数で推測します。2 すべてのトグル機能をスキップする必要があります。やり方がわからない

最初の関数のみが実行される場合、すべてのトグルをスキップする方法は?

(ちなみに「stop().animate」を試してみましたがダメでした)

これが動作する例です。変更できます: http://jsfiddle.net/xngx9/

4

1 に答える 1

0

デモ

$(function(){
    $(".square").click(function(e){
        e.stopPropagation();
        var tgl = $(this).width() === 100 ?
        $(this).stop(1).animate({"width":"200px"}, 900):
        $(this).stop(1).animate({"width":"100px"}, 900);
    });

    $(document).click(function() {
      $('.square').stop(1).animate({ "width":"100px"}, 900);  
    });
});
于 2012-05-11T15:09:34.753 に答える