.css() for 'animation-delay' 属性不能用变量设置
.css() for 'animation-delay' attribute cannot be set with variable
我无法使用变量来更改 'animation-delay' css 属性。
注意:这适用于背景颜色或其他动画属性。动画延迟也适用于字符串“10s”,但不适用于变量——即使变量明确设置为字符串。
var animationDelayTime = '10s'
$('.my-animation-class').css({
'animation-delay' : animationDelayTime
})
这个其他方法也不行:
$('.my-animation-class').css(
'animation-delay', animationDelayTime
)
目前有效:
$('.my-animation-class').css({
'animation-delay' : '10s'
})
我创建了 jsfiddle - 这对我有用。也许您在其他地方有问题?
<div class="my-animation-class"></div>
JS
$(document).ready(function(){
var animationDelayTime = '10s'
$('.my-animation-class').css({
'animation-delay' : animationDelayTime
});
});
CSS
.my-animation-class{
width:200px;
height:200px;
background:#ff0000;
-webkit-animation: mymove 5s infinite;
-webkit-animation-delay: 2s;
animation: mymove 5s infinite;
position:relative;
}
@-webkit-keyframes mymove {
from {left: 0px;}
to {left: 200px;}
}
@keyframes mymove {
from {left: 0px;}
to {left: 200px;}
}
我无法使用变量来更改 'animation-delay' css 属性。
注意:这适用于背景颜色或其他动画属性。动画延迟也适用于字符串“10s”,但不适用于变量——即使变量明确设置为字符串。
var animationDelayTime = '10s'
$('.my-animation-class').css({
'animation-delay' : animationDelayTime
})
这个其他方法也不行:
$('.my-animation-class').css(
'animation-delay', animationDelayTime
)
目前有效:
$('.my-animation-class').css({
'animation-delay' : '10s'
})
我创建了 jsfiddle - 这对我有用。也许您在其他地方有问题?
<div class="my-animation-class"></div>
JS
$(document).ready(function(){
var animationDelayTime = '10s'
$('.my-animation-class').css({
'animation-delay' : animationDelayTime
});
});
CSS
.my-animation-class{
width:200px;
height:200px;
background:#ff0000;
-webkit-animation: mymove 5s infinite;
-webkit-animation-delay: 2s;
animation: mymove 5s infinite;
position:relative;
}
@-webkit-keyframes mymove {
from {left: 0px;}
to {left: 200px;}
}
@keyframes mymove {
from {left: 0px;}
to {left: 200px;}
}