简体   繁体   English

jQuery不会使用animate:top 200px函数执行。 但是它会充满生气:高度

[英]jQuery won't execute with the animate: top 200px function. Yet it will with an animate: height

There is some straight jQuery that hides the open div when clicked not shown, but still adds the height to the navigation to make it seem like it is dropping down. 有一些笔直的jQuery在未显示时单击时会隐藏打开的div,但仍会增加导航的高度,使其看起来像是在下降。

This script works okay: 这个脚本可以正常工作:

    <script>
    $(document).ready(function(){
        $("#openNav").click(function(){
            $("#nav").animate({height: "200px"});
        });
        $("#closeNav").click(function(){
            $("#nav").fadeOut();
            $("#nav").animate({height: "100px"});
        });
    });
</script>

This doesn't animate at all when clicked: 单击时根本没有动画:

<script>
$(document).ready(function(){
    $("#openNav").click(function(){
        $("#nav").animate({top: "+100px"});
    });
    $("#closeNav").click(function(){
        $("#nav").fadeOut();
        $("#nav").animate({height: "-100px"});
    });
});

</script>

您需要DOM具有position:relativeabsolute ,以使诸如lefttop等的位置属性在css中生效。

#nav应该具有position: relativeposition: absolute用于top动画

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM