2012-08-09 47 views
0

我有一个小问题。有没有可能使用jQuery恢复函数? 我有一些点击功能与中间的行动。在点击之前,我可以恢复这些元素吗? Thx 4的帮助。功能恢复与jquery

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

回答

1

不,没有内置的方法来恢复使用jQuery的DOM操作/动画bucnch。你必须写出两个镜像对方,写出相关的代码:

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

:)我想这是唯一的方法 - thx – Lukas 2012-08-09 09:49:12

0

你可以使用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"); 
     } 
    }); 
}); 

或者你可以有,而不是使用属性被设置一个全局变量/隐藏输入元素。你也可以.addClass和.removeClass取决于元素的点击状态,并在这些CSS类中拥有你的状态。

+0

是的,我可以做到这一点,但它覆盖了所有的元素,我不想这样做.. – Lukas 2012-08-09 09:03:31

+1

@ŁukaszBorawski在这种情况下,你不得不自己去做这个DOM的直接“恢复”函数。另一种可以实现这一点的方法是在你的DOM中用一些ID复制隐藏的div中的所有“可点击”元素,并编写自己的回复,它将从div中获取原始元素并用该副本替换单击的元素,这将添加虽然下载你的页面相当大的开销。 – 2012-08-09 09:10:47

+0

这是一些想法,但我更好的办法可以把这一切行动转移到自然条件 - thx的利益 – Lukas 2012-08-09 09:53:55