jQuery的$('#divOne').animate({zIndex:-1000},2000)不起作用吗? [英] jQuery's $('#divOne').animate({zIndex: -1000}, 2000) does not work?
问题描述
我尝试了jQuery的
I tried jQuery's
$('#divOne').animate({zIndex: -1000}, 2000)
该元素的z索引为1000,但仍高于其他元素?
to that element which has a z-index of 1000, but it is still above the other elements?
(如果我使用firebug将其更改为-1000
,则它将位于其他元素下方)
(If I use firebug to change it to -1000
then it will be below other elements)
推荐答案
jQuery尝试在动画的每个步骤上向值添加一个单位.因此,不是99
而是99px
,这当然不是有效的zIndex
值.
jQuery attempts to add a unit to the value on each step of the animation. So, instead of 99
it'll be 99px
which, of course, isn't a valid zIndex
value.
似乎不可能将jQuery使用的单位设置为简单的空白字符串-它要么采用您在值中包含的单位(例如20%
-百分比单位),要么将使用
It doesn't seem possible to set the unit used by jQuery to simply a blank string -- it'll either take the unit you include in the value (e.g. 20%
- percent unit) or it will use px
.
幸运的是,您可以破解animate()
来完成这项工作:
Fortunately, you can hack animate()
to make this work:
var div = $('#divOne');
$({
z: ~~div.css('zIndex')
// ~~ to get an integer, even from non-numerical values like "auto"
}).animate({
z: -1000
}, {
step: function() {
div.css('zIndex', ~~this.z);
},
duration: 2000
});
有关~~
的详细信息,请参见此.
For more info about ~~
see this.
这篇关于jQuery的$('#divOne').animate({zIndex:-1000},2000)不起作用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!