gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 08:27:59 25 4
gpt4 key购买 nike

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

}
}

您必须在“$(document).ready(); 中设置函数 '$(window).resize();' "-Function,因为在"ready"中它只会运行一个。

希望我能帮上忙。

Demo <- 你必须改变红色 block 的 innerWindow :)

关于javascript - 更改屏幕大小时如何删除功能(菜单响应),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28450736/

25 4 0