如何在更改屏幕大小时删除功能(菜单响应)

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

本文关键字:功能 删除 菜单 响应 小时 屏幕      更新时间:2023-09-26
$(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:)