简单但棘手的显示/隐藏切换开/关组合驱使我疯狂

时间:2012-04-20 08:36:46

标签: javascript jquery toggle show-hide javascript-databinding

有一些需要显示/隐藏的div和需要知道的按钮何时打开以及何时关闭。不知何故,他们需要“与他人沟通”才能知道何时隐藏或可见。哦是的,我想对所有元素保持平滑的淡化/淡出效果。

谢谢!

我的小提琴在这里: http://jsfiddle.net/Pe9jn/

以下是我所获得的代码大部分都有效,但它有点古怪:

//hide maximize link on page load
$('.maximize_menu').css('display','none');


  //settings
  var opacity = 1, toOpacity = 0, duration = 350;
  //set opacity ASAP and events

$('.toggle_all, .toggle_all2').css('opacity',opacity).toggle(function() {
      $('#content, .maximize_menu, #menu, .minimize_menu').fadeTo(duration,toOpacity);
    }, function() {
      $('#content, .maximize_menu, #menu, .minimize_menu').fadeTo(duration,opacity);
    }                                         
  );

// this minimizes the menu and should make the mazimize_menu link visible when toggled off
$('.minimize_menu').css('opacity',opacity).toggle(function() {
      $('#menu, .minimize_menu,.maximize_menu').fadeTo(duration,toOpacity);
    }, function() {
      $('.maximize_menu, #menu, .minimize_menu, .maximize_menu').fadeTo(duration,opacity);
        $('.maximize_menu').show(duration,toOpacity);
        $('.maximize_menu').css('display','block');
    }                                                    
  );


// this maximizes the menu and should disappear once the menu is visible
$('.maximize_menu').css('opacity',opacity).toggle(function() {
      $('#menu, .minimize_menu,').fadeTo(duration,toOpacity);
    }, function() {
      $('#menu, .minimize_menu, .maximize_menu').fadeTo(duration,opacity);

    }                                                   
  );

1 个答案:

答案 0 :(得分:1)

我认为你应该重新考虑所有的逻辑,因为你实际上并没有隐藏元素,你只是将不透明度设置为0.你真正应该使用的是fadeOut()fadeIn()