方法:1、利用animation屬性給元素綁定循環(huán)旋轉(zhuǎn)動(dòng)畫;2、利用@keyframes規(guī)則設(shè)置動(dòng)畫的旋轉(zhuǎn)動(dòng)作;3、用“元素:active{animation-play-state:paused}”語句設(shè)置元素循環(huán)旋轉(zhuǎn)時(shí),點(diǎn)擊元素停止旋轉(zhuǎn)。
本教程操作環(huán)境:windows10系統(tǒng)、css3&&html5版、dell g3電腦。
css3怎樣設(shè)置元素360度循環(huán)旋轉(zhuǎn)時(shí)點(diǎn)擊停止
在css中,可以利用animation屬性給元素綁定循環(huán)旋轉(zhuǎn)動(dòng)畫;然后再使用@keyframes規(guī)則設(shè)置動(dòng)畫的旋轉(zhuǎn)動(dòng)作。
我們播放動(dòng)畫時(shí),如要暫停動(dòng)畫,就要用到animation-play-state這個(gè)屬性。animation-play-state屬性有兩個(gè)值:paused: 暫停動(dòng)畫;running: 繼續(xù)播放動(dòng)畫;
我們通過active選擇器就可以設(shè)置了,示例如下:
<!doctype html><html lang="en"><head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <title>document</title> <style> div{ width:100px; height:100px; background-color:pink; animation:fadenum 5s infinite; } @keyframes fadenum{ 100%{transform:rotate(360deg);}}div:active{ animation-play-state:paused;} </style></head><body> <div></div></body></html>輸出結(jié)果:
(學(xué)習(xí)視頻分享:css視頻教程)