PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

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

WBOY
WBOY 原创
2021-12-08 17:17:23 3743浏览

方法: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>

输出结果:

+6.gif

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

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。