0

少し質問があります。jqueryで関数を元に戻すことはできますか?途中にアクションがあるクリック機能があります。クリックする前にこの要素を状態に戻すことはできますか?Thx4ヘルプ。

$('.bottom_panel_button_02').click(function(){
    $('#recipe_panel').css('opacity','1');
    $('.default_clock, .info_top_panel .random_title, .bottom_panel_button_06').css('display','none');
    $('.bottom_main_panel_button').css('background','url("img/ap_bottom_panel_button_white.png") center bottom no-repeat')
    setTimeout(function(){
        $('.arrow_up, .arrow_down').fadeIn(300);
    },500);
    $('.main_content, .oven_panel').fadeOut(200);
});
4

2 に答える 2

1

いいえ、jQueryを使用してDOM操作/アニメーションのバッチを元に戻す組み込みの方法はありません。相互にミラーリングする2つの関数を記述し、関連するコードを記述する必要があります。

function action(){
    $('#recipe_panel').css('opacity','1');
    $('.default_clock, .info_top_panel .random_title, .bottom_panel_button_06').css('display','none');
    $('.bottom_main_panel_button').css('background','url("img/ap_bottom_panel_button_white.png") center bottom no-repeat')
    setTimeout(function(){
        $('.arrow_up, .arrow_down').fadeIn(300);
    },500);
    $('.main_content, .oven_panel').fadeOut(200);    
}

function revert(){
    $('#recipe_panel').css('opacity','0');
    $('.default_clock, .info_top_panel .random_title, .bottom_panel_button_06').css('display','block');
    $('.bottom_main_panel_button').css('background','')
    setTimeout(function(){
        $('.arrow_up, .arrow_down').fadeOut(300);
    },500);
    $('.main_content, .oven_panel').fadeIn(200);    
}

$('.bottom_panel_button_02').click(action);
$('.someOtherButton').click(revert);
于 2012-08-09T09:08:02.730 に答える
0

カスタム属性を使用して、次のようなことを行うことができます。

$(document).ready(function() {
    $('.bottom_panel_button_02').attr("clicked", "false");

    $('.bottom_panel_button_02').click(function() {
        var clicked = $(this).attr("clicked");

        if (clicked == "false") {
            // do your click function

            $(this).attr("clicked", "true");
        } else {
            // do your revert function

            $(this).attr("clicked", "false");
        }
    });
});

または、属性を使用する代わりに、グローバル変数/非表示の入力要素を設定することもできます。要素のクリックされた状態に応じて.addClassと.removeClassを作成し、これらのCSSクラスに状態を含めることもできます。

于 2012-08-09T08:59:31.307 に答える