繁体   English   中英

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

[英]How to remove function when I change screen size (menu responsive)

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

尝试这个。

$(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");

    }
}

你必须设置' $(window).resize(); '放在“ $(document).ready(); ”-函数之外,因为在“ ready”中它将仅运行。

希望我能提供帮助。

演示 < - 你必须改变红色块的innerWindow :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM