单击菜单时页面跳转到顶部

fre*_*red 1 javascript css jquery scroll

我正在创建一个左侧有固定菜单的网站,使用 jQuery 单击时可以看到该菜单。我的问题是,当我向下滚动到页面底部并且想要查看菜单时,页面会跳回到顶部。我希望在单击菜单时页面保持在当前位置。我怎样才能做到这一点?

这是使菜单进出动画的 jQuery:

$(document).ready(function(){
     $("#closeIcon").hide()
  });

$(document).ready(function(){
  $("#menuIcon").click(function(){
    $(".left").animate({width:'10%'}, "500");
    $(".right").animate({width:'90%'}, "500");
    $("#nav").animate({
                left: '30%',
              }, "500" );
    $("#menuIcon").fadeOut(500)
    $("#closeIcon").fadeIn(500)


  });
});

$(document).ready(function(){
  $("#closeIcon").click(function(){
    $(".left").animate({width:'0%'}, "500");
    $(".right").animate({width:'100%'}, "500");
    $("#nav").animate({
                left: '0',
            }, "500" );
    $("#menuIcon").fadeIn(500)
    $("#closeIcon").fadeOut(500)

  });
});
Run Code Online (Sandbox Code Playgroud)

菜单本身位于页面外,单击时它会滑入并调整主页面的大小。

Sha*_*att 5

在其上定义 javascript 函数以显示/隐藏菜单的锚标记应具有属性href="javascript:void(0)"