意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

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

来源:恒创科技 编辑:恒创科技编辑部
2024-01-15 14:26:59

方法: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视频教程)

以上就是css3怎样设置元素360度循环旋转时点击停止的详细内容,更多请关注恒创科技其它相关文章!

上一篇: css中圆角属性值能用百分比吗 下一篇: 手机怎么远程登录云服务器?