js实例教程-jquery重新播放css动画所遇问题解决

发布时间:2018-12-04 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了js实例教程-jquery重新播放css动画所遇问题解决脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

最近在做css动画,遇到需要用脚本重新播放动画的情况。例如:

css动画代码

. 代码如下:


.seed_txt_out .seed_txt h2 {
animation-name: seed-h2;
animation-duration: 2s;
animation-timing-function: ease;
animation-delay: 0s;
animation-iteration-count: 1;
animation-direction: alternate;
animation-play-state: running;
posITion: relative;
top: 10px;
}
@keyframes seed-h2
{
From {top: -120px;}
to {top: 10px;}
}


jquery调用播放

. 代码如下:


$(".seed_txt_out").children("p").removeClass("seed_txt");
$(".seed_txt_out").children("p").addClass("seed_txt");


这时候,会发现,第一次显示,动画会正确播放,但是,第二次的时候,动画就不会播放了。

后来上网查了一下,解决办法很简单,复制一个元素,把原来的去掉,在新的上面添加式样就可以了。

. 代码如下:


$(opts.txt).children("p").removeClass("seed_txt");
temp = $(opts.txt).children("p:eq(" + $(this).parent("ul").children("li").index(this) + ")");
newDiv = temp.clone(true);
temp.after(newDiv);
temp.remove();
newDiv.addClass("seed_txt");

最近在做css动画,遇到需要用脚本重新播放动画的情况。例如:

css动画代码

. 代码如下:


.seed_txt_out .seed_txt h2 {
animation-name: seed-h2;
animation-duration: 2s;
animation-timing-function: ease;
animation-delay: 0s;
animation-iteration-count: 1;
animation-direction: alternate;
animation-play-state: running;
position: relative;
top: 10px;
}
@keyframes seed-h2
{
from {top: -120px;}
to {top: 10px;}
}


jquery调用播放

. 代码如下:


$(".seed_txt_out").children("p").removeClass("seed_txt");
$(".seed_txt_out").children("p").addClass("seed_txt");


这时候,会发现,第一次显示,动画会正确播放,但是,第二次的时候,动画就不会播放了。

后来上网查了一下,解决办法很简单,复制一个元素,把原来的去掉,在新的上面添加式样就可以了。

. 代码如下:


$(opts.txt).children("p").removeClass("seed_txt");
temp = $(opts.txt).children("p:eq(" + $(this).parent("ul").children("li").index(this) + ")");
newDiv = temp.clone(true);
temp.after(newDiv);
temp.remove();
newDiv.addClass("seed_txt");

觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦! js技巧,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的js实例教程-jquery重新播放css动画所遇问题解决全部内容,希望文章能够帮你解决js实例教程-jquery重新播放css动画所遇问题解决所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。