jQuery - 改变宽度使页面跳到顶部

jQuery - Changing width makes the page jump to the top

我想让这个导航侧边栏在鼠标离开一段时间后滑开,使文本部分展开。事情是,每当滑动功能启动时,页面就会跳到顶部。没有使用“#”,我在函数末尾尝试了 overflow-y: scroll, return false, preventDefault,但没有任何效果。

这是js代码

$(document).ready(function(){
    $("#navbar").delay(5000).animate({left: "-=15%"});
    $("#navwrap").css("width","2%").css("position","fixed");
    $("#bodywrap").delay(5000).animate({width: "90%"});

    $("#navbar").mouseleave(function(){
        $(this).stop(true, true).delay(3000).animate({left: "-=15%"});
        $("#bodywrap").delay(3000).animate({width: "90%"});
        $("#navwrap").css("width","2%").css("position","fixed");
    });

    $("#navwrap").mouseenter(function(){
        $("#navbar").stop(true,false);
        $("#bodywrap").stop(true,false);
        if ($("#navbar").css("left") != "0%"){
            $("#navbar").animate({left: "0%"});
            $(this).css("width","15%").css("position","initial");
            $("#bodywrap").animate({width: "75%"});
        };
    });
});

这里是 fiddle:http://jsfiddle.net/uuw2dzry/1/

许多动画和延迟可以由 CSS

完成

http://jsfiddle.net/fkL57v9d/

您的代码过于复杂,容易产生错误和不良结果。
我会考虑以更简单的方式重新创建此页面。