在css中,可以使用animation-play-state属性控制动画的暂停,语法“animation-play-state:paused”;该属性在不同浏览器的兼容性不同,需加上对应前缀(如“-ms-”,“ -webkit-”等)。

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

动画是使元素从一种样式逐渐变化为另一种样式的效果。您可以改变任意多的样式任意多的次数。请用百分比来规定变化发生的时间,或用关键词 "from" 和 "to",等同于 0% 和 100%。

CSS3的animation直接提供一个animation-play-state的样式来控制动画的暂停处理。增加一个控制暂停样式,写动画样式的时候特别注意下不同浏览器的兼容性,加上对应的前缀。

示例:

<!DOCTYPE html><html><head><meta charset="utf-8"> <title>document</title> <style> div{    width:100px;    height:100px;    background:red;    position:relative;    animation:mymove 5s;    animation-play-state:paused;    /* Safari and Chrome */    -webkit-animation:mymove 5s;    -webkit-animation-play-state:paused;}@keyframes mymove{    from {        left:0px;    }    to {        left:200px;    }}@-webkit-keyframes mymove /* Safari and Chrome */{    from {        left:0px;    }    to {        left:200px;    }}</style></head><body><p><strong>注意:</strong> animation-play-state属性不兼容 Internet Explorer 9以及更早版本的浏览器.</p><div></div></body></html>

animation-play-state属性指定动画是否正在运行或已暂停。

注意:在JavaScript中使用此属性在一个周期中暂停动画。

animation-play-state: paused|running;
  • paused:指定暂停动画

  • running:指定正在运行的动画

推荐学习:css视频教程

本站提供的所有下载资源均来自互联网,仅提供学习交流使用,版权归原作者所有。如需商业使用,请联系原作者获得授权。 如您发现有涉嫌侵权的内容,请联系我们 邮箱:alixiixcom@163.com