[英]My jQuery Nav menu View Jumps when a link is clicked
If you look at my code pen my code pen and scroll down to the bottom of the page, and click a drop-down link the view jumps?如果您查看我的代码笔我的代码笔并向下滚动到页面底部,然后单击下拉链接,视图会跳转吗?
var nav = $('#menu > ul > li');
nav.find('li').hide();
nav.click(function () {
nav.not(this).find('li').hide();
$(this).find('li').slideToggle();
});
function openNav() {
document.getElementById("open").style.display = "none";
document.getElementById("close").style.display = "block";
$('#menu ul').slideToggle();
}
function closeNav() {
document.getElementById("open").style.display = "block";
document.getElementById("close").style.display = "none";
$('#menu ul').slideToggle();
}
Here is the update to your code:这是您的代码的更新:
//...
nav.click(function (e) {
e.preventDefault();
nav.not(this).find('li').hide();
$(this).find('li').slideToggle();
});
//...
Explanation: you have to pass the self reference and use the preventDetault()
method to override the default behavior.说明:您必须传递自引用并使用
preventDetault()
方法来覆盖默认行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.