NAVBAR无法按预期运行 - 可能是由于不正确的jQuery(窗口)。
我创建了一个纳维尔。在移动视图上,当我单击汉堡菜单时,我设置了一个控制台。它响应一次。当我调整窗口大小并再次单击时,它会响应几次。再次,它响应了10次以上的响应。这使纳维栏的设置打破了。下面,我尝试包括我认为要成为问题并删除所有样式功能的一般思想/逻辑。 console.log是否由于$(window).on(“ ressize”,handleresize);
而越来越多?我尝试添加$(window).off(“ resize”,“ handleresize);
无用。我该如何解决?
$(document).ready(function () {
// ...
function isMobileSize() {
if (window.innerWidth < 990) {
return true;
}
return false;
};
function handleResize() {
if (isMobileSize()) {
// show mobile dropdown
} else if (!isMobileSize()) {
// don't show mobile dropdown
}
};
handleResize();
$(window).on("resize", handleResize);
});
I've created a navbar. On mobile view, I set a console.log for when I click the hamburger menu. It responds once. When I resize the window and click again, it responds several times. Again, and it responds 10+ times, etc. This breaks the navbar with how I have it set up. Below, I've tried including the general idea/logic behind what I believe is to be the issue and removing all of the styling functions and such. Does console.log fire more and more due to $(window).on("resize", handleResize);
? I tried adding $(window).off("resize", handleResize);
to no avail. How can I fix this?
$(document).ready(function () {
// ...
function isMobileSize() {
if (window.innerWidth < 990) {
return true;
}
return false;
};
function handleResize() {
if (isMobileSize()) {
// show mobile dropdown
} else if (!isMobileSize()) {
// don't show mobile dropdown
}
};
handleResize();
$(window).on("resize", handleResize);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过简化生活并为此使用CSS?
https://codepen.io/panchroma/penchroma/pen/pen/pen/pen/xwzzozozozy
>
在文档的头部添加一个视口元素
,并在移动下拉列表中添加一类,以便您可以使用CSS
css 对目标进行定位。
Have you considered simplifying your life and using CSS for this?
https://codepen.io/panchroma/pen/XWZZozy
HTML
Add a viewport metatag in the head of your doc
And add a class to your mobile dropdown so you can target it with your CSS
CSS