CSS Code implementation

Source: Internet
Author: User

Pure CSS Implementation
Below we explore, the use of pure CSS can be implemented.

Hover pseudo-class implementation

Use the hover pseudo-class to control the pause of the animation style when the mouse hovers over the button.

The key code is as follows:

<div class= "btn Stop" >stop</div>
<div class= "Animation" ></div>

<style>
. stop:hover ~. Animation {
animation-play-state:paused;
}
</style>
Demo--Pure CSS to achieve the pause and play of CSS Animation (Hover):

Of course, this method is not smart enough, if you release the freedom of the mouse, click on the pause, and then click on the play is good. Is there any other way?

Checked pseudo-class implementation

Previous article "Talk about some interesting CSS topics (eight)--Pure CSS Navigation bar tab switching Scheme" also talked about, using radio tag checked pseudo class, plus <label for> implement pure CSS capture click things.

And you can control some CSS styles with the clicked element. The implementation is as follows:

<input id= "Stop" type= "Radio" name= "Playanimation"/>
<input id= "Play" type= "Radio" name= "Playanimation"/>

<div class= "box" >
<label for= "Stop" >
<div class= "BTN" >stop</div>
</label>
<label for= "Play" >
<div class= "BTN" >play</div>
</label>
</div>

<div class= "Animation" ></div>
Some key CSS code:

. Animation {
animation:move 2s linear infinite alternate;
}

#stop: Checked ~. Animation {
animation-play-state:paused;
}

#play: Checked ~. Animation {
animation-play-state:running;
}
We hope that when #stop and #play two radio are clicked, the. Animation elements are given animation-play-state:paused or Animation-play-state:running respectively. And they can only take effect one, so you need to give two radio tags the same name attribute.

CSS Code implementation

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.