Jquery 浏览器调整大小时隐藏侧菜单

Jquery 浏览器调整大小时隐藏侧菜单,jquery,Jquery,用户单击链接目录,它显示为侧菜单。 如果浏览器大小调整到1448px以下,则侧菜单会淡出 因此,在点击目录链接后,将浏览器的大小调整到1448px以下,然后调整到1448px以上 如何使侧菜单再次自动淡出 var button = $("a#contents_link"); // the TOC link var toc = $('#table-of-contents'); // the TOC div to show var browser = $(window);

用户单击链接目录,它显示为侧菜单。 如果浏览器大小调整到1448px以下,则侧菜单会淡出

因此,在点击目录链接后,将浏览器的大小调整到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();
        }
    });

我对您在第一个IF语句中检查TOC可见性的代码感到困惑。你不应该把它改写成:

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