在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视频教程。
的方法是什么