jquery重新播放css動畫所遇問題解決
更新時(shí)間:2013年08月21日 19:14:27 作者:
做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調(diào)用播放
$(".seed_txt_out").children("div").removeClass("seed_txt");
$(".seed_txt_out").children("div").addClass("seed_txt");
這時(shí)候,會發(fā)現(xiàn),第一次顯示,動畫會正確播放,但是,第二次的時(shí)候,動畫就不會播放了。
后來上網(wǎng)查了一下,解決辦法很簡單,復(fù)制一個(gè)元素,把原來的去掉,在新的上面添加式樣就可以了。
$(opts.txt).children("div").removeClass("seed_txt");
temp = $(opts.txt).children("div:eq(" + $(this).parent("ul").children("li").index(this) + ")");
newDiv = temp.clone(true);
temp.after(newDiv);
temp.remove();
newDiv.addClass("seed_txt");
這里有個(gè)鏈接,老外解決的辦法。還說了其它情況。遇到類似問題的朋友可以參考下,當(dāng)然,是英文的。
http://css-tricks.com/restart-css-animation/
css動畫代碼
復(fù)制代碼 代碼如下:
.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調(diào)用播放
復(fù)制代碼 代碼如下:
$(".seed_txt_out").children("div").removeClass("seed_txt");
$(".seed_txt_out").children("div").addClass("seed_txt");
這時(shí)候,會發(fā)現(xiàn),第一次顯示,動畫會正確播放,但是,第二次的時(shí)候,動畫就不會播放了。
后來上網(wǎng)查了一下,解決辦法很簡單,復(fù)制一個(gè)元素,把原來的去掉,在新的上面添加式樣就可以了。
復(fù)制代碼 代碼如下:
$(opts.txt).children("div").removeClass("seed_txt");
temp = $(opts.txt).children("div:eq(" + $(this).parent("ul").children("li").index(this) + ")");
newDiv = temp.clone(true);
temp.after(newDiv);
temp.remove();
newDiv.addClass("seed_txt");
這里有個(gè)鏈接,老外解決的辦法。還說了其它情況。遇到類似問題的朋友可以參考下,當(dāng)然,是英文的。
http://css-tricks.com/restart-css-animation/
相關(guān)文章
jQuery基于xml格式數(shù)據(jù)實(shí)現(xiàn)模糊查詢及分頁功能的方法
這篇文章主要介紹了jQuery基于xml格式數(shù)據(jù)實(shí)現(xiàn)模糊查詢及分頁功能的方法,涉及jQuery使用ajax技術(shù)針對xml格式數(shù)據(jù)的讀取、模糊查詢及分頁顯示等相關(guān)操作技巧,需要的朋友可以參考下2016-12-12jQuery通過ajax方法獲取json數(shù)據(jù)不執(zhí)行success的原因及解決方法
這篇文章主要介紹了jQuery通過ajax方法獲取json數(shù)據(jù)不執(zhí)行success的原因及解決方法的相關(guān)資料,需要的朋友可以參考下2016-10-10jQuery實(shí)現(xiàn)的placeholder效果完整實(shí)例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的placeholder效果,可實(shí)現(xiàn)輸入框提示文字的功能,并且針對焦點(diǎn)的情況判定是否顯示,非常簡單實(shí)用,需要的朋友可以參考下2016-08-08基于jquery實(shí)現(xiàn)鼠標(biāo)左右拖動滑塊滑動附源碼下載
這篇文章主要介紹了基于jquery實(shí)現(xiàn)鼠標(biāo)左右拖動滑塊滑動附源碼下載 的相關(guān)資料,需要的朋友可以參考下2015-12-12