我正试图让它发挥作用,但由于某种未知的原因,图像没有变化。。看看我创建的JSfiddle
here
。(当你悬停在图像上时,图像应该会跳跃,当你悬停时,图像会向下浮动)。
$(document).ready(function() {
$('#hover-image').hover(
function() {
// Over
$(this).animate({
'background-position': 'center top'
}, 5000);
},
function() {
// Out
$(this).animate({
'background-position': 'center center'
}, 5000);
}
);
});
#hover-image {
width: 300px;
height: 300px;
background: url(http://icons.iconarchive.com/icons/artbees/paradise-fruits/256/Banana-icon.png);
background-repeat: no-repeat;
background-position: center center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<div id="hover-image"></div>
编辑:我现在发现你不能在非数字css值上设置动画。将背景位置更改为使用百分比解决了问题。