我的 JQuery 运行良好,可以让 Logo 弹出移动导航,但几分钟后就不起作用了。单击 Logo 时,它不再更改 UL 的显示 这是我的代码:
$(document).ready(function() {
checkSize();
});
function checkSize(){
if ($("ul, #left img:nth-of-type(2)").css("display") == "none" ) {
$("#click").on('click',function() {
$("ul, #left img:nth-of-type(2)").toggleClass("show-items");
});
}
}
谢谢。
最佳答案
Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.
您的 jQuery 可以工作,只有您指定运行一次。
更新:
要在每次窗口大小更改时运行脚本,请使用 .resize()
The resize event is sent to the window element when the size of the browser window changes:
// run once the document is lodaded
$(document).ready(checkSize);
// run on resize
$( window ).resize(checkSize);
关于javascript - 一两分钟后 JQuery 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62316965/