2012-03-14 63 views
0

用户单击链接“目录”,它将显示为侧边菜单。 如果浏览器调整到1448px以下,那么侧边菜单会执行fadeOut()。浏览器调整大小时的隐藏侧菜单

因此,在已经点击“目录”链接,下面调整的1448px浏览器,那么上述1448px调整...

我怎么能自动淡入()再次得到侧面菜单?

var button = $("a#contents_link"); // the TOC link 
    var toc = $('#table-of-contents'); // the TOC div to show 
    var browser = $(window);   // getting the browser width 


    toc.hide();       // hide the TOC div upon loading the page 

    button.click(function (event) { // toggling the TOC div 
     toc.fadeToggle(300); 
     event.preventDefault(); 
    }); 

    $(browser).resize(function() { 
     if ((toc.is(':visible')) && (browser.width() >=1449)) { 
      toc.fadeIn(); 
     } else if((toc.is(':visible')) && (browser.width() <=1448)){ 
      toc.fadeOut(); 
     } 
    }); 

回答

0

我对你的代码感到困惑,你在第一个IF语句中检查TOC的可见性。您不应该将其重写为:

$(browser).resize(function() { 
    if ((toc.is(':hidden')) && (browser.width() >=1449)) { 
     toc.fadeIn(); 
    } else if((toc.is(':visible')) && (browser.width() <=1448)){ 
     toc.fadeOut(); 
    } 
}); 
相关问题