更改屏幕尺寸时如何删除功能(菜单响应)

时间:2015-02-11 09:28:45

标签: javascript jquery css

$(document).ready(function () {
    // get width of screen
    var Docwidth = 0;
    $(window).resize(function () {
        Docwidth = $(document).width();

        //if width of document smaller screen

        if (Docwidth < 768) {
            //turn on accordion
            $('#accordion').accordion({
                heightStyle: false
            });
        } else {
            // turn off function when i change screen size
            $('#accordion').accordion("disable");
        }
    });
});

1 个答案:

答案 0 :(得分:0)

试试这个。

$(document).ready(function () {
// get width of screen
var Docwidth = 0;
    testWindowWidth();
});

$(window).resize(function () {
   testWindowWidth();
});

function testWindowWidth(){
     Docwidth = $(document).width();   

    //if width of document smaller screen

    if (Docwidth < 768) {
        //turn on accordion
       $('#accordion').accordion({
            heightStyle: false
        });

    } else {
        // turn off function when i change screen size

        $('#accordion').accordion("disable");

    }
}

您必须设置功能&#39; $(窗口).resize(); &#39;超出&#34; $(文档).ready(); &#34; -Function,因为在&#34; ready&#34;它只会运行。

希望我能提供帮助。

Demo&lt; - 您必须更改红色块的innerWindow:)