在css中,可以利用“:hover”选择器和“animation-play-state”属性实现鼠标悬浮停止动画效果,语法为“动画元素:hover{animation-play-state:paused;}”。
本教程操作环境:windows10系统、CSS3&&HTML5版、Dell G3电脑。
css3怎样实现鼠标悬浮停止动画效果
在css中,可以利用animation属性给元素绑定动画;然后再使用@keyframes规则设置动画的作。
我们播放动画时,如要暂停动画,就要用到animation-play-state这个属性。animation-play-state属性有两个值:paused: 暂停动画;running: 继续播放动画;
我们通过hover选择器选中鼠标悬浮在元素时的状态,就可以进行暂停动画。
下面我们通过示例来看一下,示例如下:
<!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:hover{ animation-play-state:paused; } </style> </head> <body> <div></div> </body> </html>
输出结果:
大家感兴趣的话,可以继续访问:css视频教程。
以上就是css3怎样实现鼠标悬浮停止动画效果的详细内容,更多请关注php中文网其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。