Search code examples
javascriptjquerycssrevert

Function revert with jquery


I have a little question. Is there any possible to revert function with jquery? I have some click function with actions in the middle of it. Can i revert this elements to condition before click? Thx 4 help.

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

Solution

  • No, there is no built-in way to revert a bucnch of DOM manipulations/animations using jQuery. You'll have to write 2 functions which mirror each other and write the code associated:

    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);