只看到update3:
我有改变背景图像的css3动画:
@-webkit-keyframes changeImage{
0%{background-image: url("images/img-1.png");}
50%{background-image: url("images/img-2.png");}
100%{background-image: url("images/img-3.png");}
}
#img{
-webkit-animation: changeImage 1s;
-webkit-animation-play-state: running;
-webkit-animation-fill-mode: both;
-webkit-animation-iteration-count: 1;
}但同样的动画,如果我做悬停,将不会像#img,#img:hover{...}那样,只有css3。无论如何,我希望我的动画迭代数无限的悬停#img。
那么,如何使用jquery或javascript来实现呢?
我试过这样做:
$('#img').hover(function(){
$(this).css({'webkitAnimation':'changeImage 1s','webkitAnimationIterationCount':'infinite'});
});但没有工作的运气。有什么建议吗?
更新:
虽然我了解到,如果在css3中运行play状态,则可以执行以下工作:
$('#img').click(function(){
$(this).css({'webkitAnimationPlayState':'paused'}); //pause the animation
});但停下来之后就没有了:
$('#img').hover(function(){
$(this).css({'webkitAnimationPlayState':'paused'});
$(this).css({'webkitAnimationPlayState':'running','webkitAnimationIterationCount':'infinite'}); // doing nothing
});Update2:
我认为我的关键问题是背景图像,当停止动画和重放动画时,我需要改变背景图像,因为它是在停止后的img-3。所以下面的也是不管用的,我很惊讶!
$('#img').hover(function(){//after animation stops and hoverd to
$(this).css({'background-image':'url(images/img-1.png'});
});Update3:
下面是应用css3动画更改背景图像的演示程序:
当我在css样式表中将css3动画重命名为#img到#imgz时,这个演示程序会在单击按钮时更改背景。现在将其更改为#img并运行,然后您将发现按钮单击不会更改背景图像!是的,居然没起作用,为什么?
发布于 2014-04-02 09:19:44
请按下列连结操作:
<img src="http://dummyimage.com/300x300/000/fff&text=image" class="graphs" />
.graphs {
-webkit-animation-iteration-count:infinite;
-webkit-animation-timing-function:linear;
-webkit-animation-name:orbit;
-webkit-animation-duration:2s;
-moz-animation-iteration-count:infinite;
-moz-animation-timing-function:linear;
-moz-animation-name:orbit;
-moz-animation-duration:2s;
}
@-webkit-keyframes orbit {
from { -webkit-transform:rotateY(0deg) }
to { -webkit-transform:rotateY(360deg) }
}
@-moz-keyframes orbit {
from { -moz-transform:rotateY(0deg) }
to { -moz-transform:rotateY(360deg) }
}发布于 2014-04-02 10:35:44
我希望它能帮到你。JSFiddle
https://stackoverflow.com/questions/22806342
复制相似问题