gpt4 book ai didi

javascript - jQuery 循环动画

转载 作者:行者123 更新时间:2023-12-02 20:32:51 24 4
gpt4 key购买 nike

嘿,我正在尝试让下面的代码正常工作,以便当鼠标移到“bug”上时,它会产生动画效果,就像它在飞翔一样。

这是我当前的代码:

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

var navDuration = 150; //time in miliseconds
var navJumpHeight = "0.45em";

$('#bug1').hover(function() {
$(this).animate({ top : "-="+navJumpHeight }, navDuration);
}, function() {
$(this).animate({ top : "15px" }, navDuration);
});

});
</script>
<body>
<a href="google.com"><img src="images/bug_05.png" width="90" height="73" id="bug1" /></a>
</body>

上面的代码似乎根本没有移动图像。我正在尝试制作一种循环效果,就像当用户将鼠标放在它上面时, bug 会飞(悬停)一点。

任何帮助都会很棒! :o)

大卫

最佳答案

要使 top 样式产生任何效果,您需要定位元素,在本例中是 position:relative,如下所示:

​#bug1 { position: relative; }​

You can see it working here 。您可能还希望在 mouseleave 动画中使用 0px 而不是 15px,因此它会重置到原始位置 like this .

关于javascript - jQuery 循环动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3798696/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com