Jquery动画处理输入提交按钮?
我有一个href按钮,上面有一段javascript动画,可以让篮子在悬停时上下跳跃。但是,我需要将href链接更改为输入提交按钮,并且我似乎无法使动画与输入按钮一起正常工作 这是我用于动画的javascriptJquery动画处理输入提交按钮?,jquery,jquery-animate,Jquery,Jquery Animate,我有一个href按钮,上面有一段javascript动画,可以让篮子在悬停时上下跳跃。但是,我需要将href链接更改为输入提交按钮,并且我似乎无法使动画与输入按钮一起正常工作 这是我用于动画的javascript <script type="text/javascript"> $(document).ready(function(){ $(".button").hover(function(){ $(":not(:animated)",
<script type="text/javascript">
$(document).ready(function(){
$(".button").hover(function(){
$(":not(:animated)", this)
// first jump
.animate({top:"-=6px"}, 200).animate({top:"+=6px"}, 200)
// second jump
.animate({top:"-=3px"}, 100).animate({top:"+=3px"}, 100)
// the last jump
.animate({top:"-=2px"}, 100).animate({top:"+=2px"}, 100);
});
})
</script>
$(文档).ready(函数(){
$(“.button”).hover(函数(){
$(“:非(:动画)”,此)
//第一跳
.animate({top:+=6px},200)。animate({top:+=6px},200)
//第二跳
.animate({top:+=3px},100)。animate({top:+=3px},100)
//最后一跳
.animate({top:+=2px},100)。animate({top:+=2px},100);
});
})
这是HTML
<div class="addbasketbut">
<a class="button" href="#">
<img src="template_images/basketbutton.png" alt="" />Add to Basket
</a>
</div>
这是一个原始按钮的工作界面
我对Jquery不太有经验,因此非常感谢您的帮助。一种可能的方法: 对于输入按钮,您可以使用CSS中的背景图像覆盖提交按钮(我认为这可能是唯一的方法) 为了给图像设置动画,可以使用
$('.button')。在悬停状态下设置动画({“backgroundPosition”:POSITION})
,在悬停状态下更改SUBMIT按钮的背景图像位置
我将jquery代码更新为
$(document).ready(function () {
$(".addbasketbut").hover(function () {
$(".image:not(:animated)", this)
// first jump
.animate({
top: "-=6px"
}, 200).animate({
top: "+=6px"
}, 200)
// second jump
.animate({
top: "-=3px"
}, 100).animate({
top: "+=3px"
}, 100)
// the last jump
.animate({
top: "-=2px"
}, 100).animate({
top: "+=2px"
}, 100);
});
})
还有这个的html
<div class="addbasketbut">
<img src="template_images/basketbutton.png" class="image" alt=""/>
<input class="button" type="submit" value="Submit">
</div>
这似乎奏效了。我不确定这是否是最优雅的解决方案。。。但事实是如此:) 你好,伊亚诺,谢谢你的建议,但它不起作用。原因是该按钮使用了两个图像。一个用于设置按钮本身样式的背景图像(不设置动画)和另一个设置动画的图像。我已经用第一个背景图像设置了输入按钮的样式,但是我似乎无法设置第二个图像的动画。我尝试将输入按钮封装在一个div中,并将图像添加到div中,但这只是使图像和输入按钮都具有动画效果。但我只想让篮子图像动画,而不是整个按钮。