0

我有一个小问题。有没有可能用jquery恢复功能?我有一些点击功能,中间有动作。我可以在点击之前将此元素恢复为条件吗?谢谢 4 帮助。

$('.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

You could do something like this using custom attributes:

$(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");
        }
    });
});

Alternatively you could have a global variable / hidden input element that is set, instead of using attributes. You could also .addClass and .removeClass depending on the clicked state of the element and have your states in these CSS classes.

于 2012-08-09T08:59:31.307 回答