Javascript 单击链接时使覆盖菜单消失
首先,这个问题只适用于该网站的移动版本,因此您必须将浏览器缩小到小于1000像素的宽度才能看到菜单 在移动布局上,我有一个按钮,可以显示一个带有4个链接的覆盖图。有一个“X”关闭覆盖,但我希望它关闭时,用户点击的链接,以及。到目前为止,我还没能让它工作。以下是我使用的代码: 这是我正在尝试调整的javascript,以使其正常工作:Javascript 单击链接时使覆盖菜单消失,javascript,css,Javascript,Css,首先,这个问题只适用于该网站的移动版本,因此您必须将浏览器缩小到小于1000像素的宽度才能看到菜单 在移动布局上,我有一个按钮,可以显示一个带有4个链接的覆盖图。有一个“X”关闭覆盖,但我希望它关闭时,用户点击的链接,以及。到目前为止,我还没能让它工作。以下是我使用的代码: 这是我正在尝试调整的javascript,以使其正常工作: $(document).ready(function(){ // Add smooth scrolling to all links $("a").on(
$(document).ready(function(){
// Add smooth scrolling to all links
$("a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
});
$('#hider').click(function() {
$('menu').addClass('hidemenu');
});
更改
$('menu').addClass('hidemenu')代码>到$('#菜单')。addClass('hidemenu')代码>。在你的代码笔中,你需要添加jquery,它看起来没有任何区别。我在我的原始帖子中编辑了代码,加入了我正在使用的另一个脚本,我认为这可能会干扰我无法成功实现的脚本。