PHP前端开发

css3怎样设置元素360度循环旋转时点击停止

百变鹏仔 4周前 (09-20) #CSS
文章标签 时点
方法:1、利用animation属性给元素绑定循环旋转动画;2、利用@keyframes规则设置动画的旋转动作;3、用“元素:active{animation-play-state:paused}”语句设置元素循环旋转时,点击元素停止旋转。

本教程操作环境:windows10系统、CSS3&&HTML5版、Dell G3电脑。

css3怎样设置元素360度循环旋转时点击停止

在css中,可以利用animation属性给元素绑定循环旋转动画;然后再使用@keyframes规则设置动画的旋转动作。

我们播放动画时,如要暂停动画,就要用到animation-play-state这个属性。animation-play-state属性有两个值:paused: 暂停动画;running: 继续播放动画;

立即学习“前端免费学习笔记(深入)”;

我们通过active选择器就可以设置了,示例如下:

<!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>

输出结果:

(学习视频分享:css视频教程)