动画背景位置总是返回 50%?
我正在尝试做一个非常非常简单的鼠标悬停,以动画方式改变背景位置。
js
$('li.services_w')
.css({
backgroundPosition: "0px 0px"
})
.mouseover(function () {
$(this).stop().animate({
backgroundPosition: "(0px -35px)"
}, {
duration: 500
})
})
.mouseout(function () {
$(this).stop().animate({
backgroundPosition: "(0px 0px)"
}, {
duration: 200,
complete: function () {
$(this).css({
backgroundPosition: "0px 0px"
})
}
})
});
除了每次运行此代码时,背景总是返回 background-position: 0 50%
作为鼠标悬停的结果。不管怎样我也改变这些数字!我向你保证这是我唯一使用的 javascript。
css
.services_w {
height: 35px;
overflow:hidden;
background: url("../img/services_w.jpg") repeat 0px 0px;
}
.services_w:hover {
background-position: 0px -35px;
}
html
<div class="grid_10 nav">
<ul class="lavaLamp">
<li class="current"><a href="index.html">home</a></li>
<li class="services_w"><a href="services.html">services</a></li>
...
I'm trying to do a very very simple mouseover that animates a change in background position.
js
$('li.services_w')
.css({
backgroundPosition: "0px 0px"
})
.mouseover(function () {
$(this).stop().animate({
backgroundPosition: "(0px -35px)"
}, {
duration: 500
})
})
.mouseout(function () {
$(this).stop().animate({
backgroundPosition: "(0px 0px)"
}, {
duration: 200,
complete: function () {
$(this).css({
backgroundPosition: "0px 0px"
})
}
})
});
Except everytime I run this code, the background always returns background-position: 0 50%
as the outcome of the mouseover. No matter what I change those numbers too! I assure you this is the only javascript I am using.
css
.services_w {
height: 35px;
overflow:hidden;
background: url("../img/services_w.jpg") repeat 0px 0px;
}
.services_w:hover {
background-position: 0px -35px;
}
html
<div class="grid_10 nav">
<ul class="lavaLamp">
<li class="current"><a href="index.html">home</a></li>
<li class="services_w"><a href="services.html">services</a></li>
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除额外的
"(....)"
,这是无效的 CSS,如下所示:或者使用
.hover()
并直接指定持续时间:Remove the extra
"(....)"
that's invalid CSS, like this:Or a bit cleaner using
.hover()
and specifying the duration directly: