ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

web前端:原生css球体弹跳效果,animation动画keyframes应用,指定停止动画animation-play-state:paused

2021-01-15 22:33:27  阅读:161  来源: 互联网

标签:动画 web 50% 300px animation wrap margin


1.less

* {
    margin: 0;
    padding: 0;
    #wrap {
        position: absolute;
        width: 600px;
        height: 600px;
        background: url(../img/my-logo-2.png) repeat;
        background-size: 50px;
        border: 1px solid #000000;
        border-radius: 50%;
        top: 50%;
        left: 50%;
        margin-left: -300px;
        margin-top: -300px;
        
        &:hover #wrap-inner{
            //animation-play-state:动画执行的运行/暂停,默认值running,pause暂停
            animation-play-state: paused;
        }
        
        #wrap-inner {
            position: absolute;
            width: 300px;
            height: 300px;
            background: tomato;
            border: 2px solid white;
            border-radius: 50%;
            box-shadow: 2px 2px 5px tomato;
            font: 30px/300px "微软雅黑";
            text-align: center;
            color: white;
            top: 50%;
            left: 50%;
            margin-left: -150px;
            margin-top: -150px;
            animation-name: rotated;
            animation-duration: 1.5s;
            //animation-timing-function: linear;
            animation-timing-function: cubic-bezier(.12,1.36,.65,-0.28);
            //direction:normal(from→to)reverse反转(to→from)、alternate(from→to→from...循环)/alternate-reverse
            animation-direction: alternate;
            animation-iteration-count: 6;
            //延迟为外部动画
            animation-delay: 1s;
            /*元素在动画外的状态: from之前to之后
              1. backwards与from一致=动画开始的动作,结束回归原位
              2. forwards与to一致=动画结束的动作,结束不回归原位
              3. both=动画开始/结束的动作,开始/结束不回归原位
            */
            //animation-fill-mode: backwards;
            //animation-fill-mode: forwards;
            animation-fill-mode: both;
        }
    }
    @keyframes rotated {
        from {
            //Y轴:x+100px
            transform: translateY(100px);
        }
        to {
            //Y轴:x-100px
            transform: translateY(-100px);
        }
    }
}

2.css

* {
  margin: 0;
  padding: 0;
}
* #wrap {
  position: absolute;
  width: 600px;
  height: 600px;
  background: url(../img/my-logo-2.png) repeat;
  background-size: 50px;
  border: 1px solid #000000;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  margin-left: -300px;
  margin-top: -300px;
}
* #wrap:hover #wrap-inner {
  animation-play-state: paused;
}
* #wrap #wrap-inner {
  position: absolute;
  width: 300px;
  height: 300px;
  background: tomato;
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 2px 2px 5px tomato;
  font: 30px/300px "微软雅黑";
  text-align: center;
  color: white;
  top: 50%;
  left: 50%;
  margin-left: -150px;
  margin-top: -150px;
  animation-name: rotated;
  animation-duration: 1.5s;
  animation-timing-function: cubic-bezier(0.12, 1.36, 0.65, -0.28);
  animation-direction: alternate;
  animation-iteration-count: 6;
  animation-delay: 1s;
  /*元素在动画外的状态: from之前to之后
              1. backwards与from一致=动画开始的动作,结束回归原位
              2. forwards与to一致=动画结束的动作,结束不回归原位
              3. both=动画开始/结束的动作,开始/结束不回归原位
            */
  animation-fill-mode: both;
}
@keyframes rotated {
  from {
    transform: translateY(100px);
  }
  to {
    transform: translateY(-100px);
  }
}

3.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>动画模式@keyframes{}</title>
	</head>
	<body>
		<div id="wrap">
			<div id="wrap-inner">cevent</div>
		</div>
	</body>
	<link rel="stylesheet" href="css/less034.css" />
</html>

4.效果图

cevent

标签:动画,web,50%,300px,animation,wrap,margin
来源: https://blog.csdn.net/weixin_37056888/article/details/112689051

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有