[英]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:relative
或absolute
,以使诸如left
, top
等的位置属性在css中生效。
#nav
应该具有position: relative
或position: absolute
用于top
动画
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.