【发布时间】:2013-02-10 07:54:12
【问题描述】:
我想更改 jquery 动画中的背景图像位置。但是我的代码不起作用。谁能帮我把它短路。
以下是我的代码
CSS
#pnav a{
background:url(http://www.us-bingo.com/images/Tickets/Solid-Color-Tyvek-Wrist-Tickets-lg.gif) 0 0 no-repeat;
display:block;
width:20px;
height:42px;
}
jQuery
$('#pnav a')
.hover(function () {
$(this).stop().animate({
'background-position' : '(0px -42px)'
}, 150);
}, function () {
$(this).stop().animate({
'background-position' : '(0 0)'
}, 150);
});
html
<div id="pnav">
<a href="#">123</a>
</div>
提前谢谢你。
【问题讨论】:
-
我猜,您可能没有在 document.ready 中包含您的脚本。这就是为什么在文档未准备好时调用它的原因。我已经更新了我的代码。它是一个简单的html。它的工作。