前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >animation-play-state 属性——动画示例

animation-play-state 属性——动画示例

作者头像
Html5知典
发布2019-11-26 15:16:10
4680
发布2019-11-26 15:16:10
举报
文章被收录于专栏:Html5知典Html5知典

用途

animation-play-state 规定动画是否正在运行或暂停。默认是 “running”。

语法

代码语言:javascript
复制
/* Single animation */ 
animation-play-state: running; a
nimation-play-state: paused; 

/* Multiple animations */ 
animation-play-state: paused, running, running; 

/* Global values */ 
animation-play-state: inherited; 
animation-play-state: initial; 
animation-play-state: unset;

描述

running

动画正在运行。

paused

动画已暂停。

例子

默认设定值paused,鼠标移动到例子上,状态值修改为running。

代码语言:javascript
复制
/* HTML */
<div class="box"> 
    <div class="container-box"> 
        <div class="el top"></div> 
        <div class="el right"></div> 
        <div class="el left"></div> 
        <div class="el bottom"></div> 
     </div> 
 </div>    
 
/* CSS */
@keyframes top { 
15% {    
    transform: translate(0, 0) rotate(0);} 
60% {    
    transform: translate(-30px, -30px) rotate(20deg);} 
100% {    
    transform: translate(0, 0) rotate(90deg); } } 
@keyframes right { 
15% {     
    transform: translate(0, 0) rotate(0);} 
60% {     
    transform: translate(30px, -30px) rotate(-20deg); } 
100% {     
    transform: translate(0, 0) rotate(-90deg);} } 
@keyframes left { 
15% {    
    transform: translate(0, 0) rotate(0);} 
60% {    
    transform: translate(-30px, 30px) rotate(-20deg);} 
100% {   
     transform: translate(0, 0) rotate(-90deg);} } 
@keyframes bottom { 
15% {    
    transform: translate(0, 0) rotate(0);} 
60% {     
    transform: translate(30px, 30px) rotate(20deg);} 
100% {    
    transform: translate(0, 0) rotate(90deg);} } 
.box { 
    position: relative; 
    width:200px; 
    height:100px; } 
.box .container-box { 
    position: absolute; 
    background: #b2dbfb; 
    width: 60px; 
    height: 60px; 
    left: 50%; 
    margin-left: -30px; 
    top: 50%; 
    margin-top: -30px; 
    transform: rotate(45deg); 
    cursor: pointer; } 
.box .container-box:hover .el { 
    animation-play-state: running; } 
.box .container-box .el { 
    display: inline-block; 
    width: 30px; 
    height: 30px; 
    background: #2196F3; 
    margin: -3px; 
    border: 2px solid #2196F3; 
    border-radius: 2px; } 
.box .container-box .top { 
    animation: top 1s linear infinite; 
    animation-play-state: paused; } 
.box .container-box .right { 
    animation: right 1s linear infinite; 
    animation-play-state: paused; } 
.box .container-box .left { 
    animation: left 1s linear infinite; 
    animation-play-state: paused; } 
.box .container-box .bottom { 
    animation: bottom 1s linear infinite; 
    animation-play-state: paused; }

执行结果

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2018-11-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Html5知典 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档