Solve the Problem of jquery re-playing css animations _ jquery

Source: Internet
Author: User
When you need to re-play the animation with a script for css animation, I would like to share with you the following. If you are interested, please refer to it and hope to help you with css animation recently, you may need to use a script to play the animation again. For example:

Css animation code

The Code is as follows:


. Seed_txt_out. seed_txt h2 {
Animation-name: seed-h2;
Animation-duration: 2 s;
Animation-timing-function: progress;
Animation-delay: 0 s;
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 calls playback

The Code is as follows:


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


At this time, you will find that the animation will be correctly played for the first time, but the animation will not be played for the second time.

Later, I checked it online. The solution was very simple. Copy an element, remove the original one, and add the style on the new one.

The Code is as follows:


Optional (opts.txt). children ("p"). removeClass ("seed_txt ");
Temp = logs (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 ");


There is a link here to solve the problem for foreigners. I also talked about other cases. If you encounter a similar problem, refer to, of course, English.
Http://css-tricks.com/restart-css-animation/
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.