CSS3 keyframes 实战:简易的循环弹跳动画

题外话

keyframes的小练习,相信对刚掌握了keyframes理论知识的有些帮助;
百看不如一练,动手吧。

注意: 建议用chrome或者chromium内核的浏览器进行浏览器,Firefox也行

基础理论

  • keyframes是CSS3才引进的 … 使用方法是前面@keyframes Demo , Demo是自定义动画名字
  • 仅支持百分比为进度条和form-to!!!两者可以混用
  • animation有八个参数,可以分开写,可以综合写(一般一起写);
    • animation-name 规定 @keyframes 动画的名称。
    • animation-duration 规定动画完成一个周期所花费的秒或毫秒。默认是 0。
    • animation-timing-function 规定动画的速度曲线。默认是 “ease”。
    • animation-delay 规定动画何时开始。默认是 0。
    • animation-iteration-count 规定动画被播放的次数。默认是 1。
    • animation-direction 规定动画是否在下一周期逆向地播放。默认是 “normal”。
    • animation-play-state 规定动画是否正在运行或暂停。默认是 “running”。
    • animation-fill-mode 规定对象动画时间之外的状态。

综合写法: animation : name 1s linear 1s inifinite alternate running both;

效果图

这里写图片描述

这里写图片描述

这里写图片描述

Live Demo

代码

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>keyframes</title>
		<style>
			.demo {
				width: 200px;
				height: 200px;
				text-align: center;
				line-height: 200px;
				background-color: #fe043c;
				position: relative;
				left: 50%;
				margin-left: -100px;
				-webkit-animation: Demo 6s ease-in-out infinite alternate running forwards;
				animation: Demo 6s ease-in-out infinite alternate running forwards;
			}
			.demo1 {
				width: 100px;
				height: 100px;
				text-align: center;
				line-height: 100px;
				background-color: #fe043c;
				position: absolute;
				left: 30%;
				margin-left: -100px;
				-webkit-animation: Demo1 6s ease-in-out infinite alternate running forwards;
				animation: Demo1 6s ease-in-out infinite alternate running forwards;
			}

			@-webkit-keyframes Demo {
				20% {
					background-color: #f68c1b;
					top: 50px;
					border-radius: 20%;
				}
				40% {
					background-color: #31b32c;
					top: 100px;
					border-radius: 40%;
					-webkit-transform: rotate(90deg) scale(1.4);
					transform: rotate(90deg) scale(1.4);
				}

				60% {
					background-color: #1b8df6;
					top: 200px;
					border-radius: 60%;
					-webkit-transform: scale(.4) translateX(300);
					transform: scale(.4) translateX(300);
				}
				80% {
					background-color: #ba38d5;
					top: 300px;
					border-radius: 80%;
					-webkit-transform: rotate(-90deg) scale(1.4);
					transform: rotate(-90deg) scale(1.4);
				}
				100% {
					background-color: #2bbada;
					top: 400px;
					border-radius: 100%;
				}
			}

			@keyframes Demo {
				20% {
					background-color: #f68c1b;
					top: 50px;
					border-radius: 20%;
				}
				40% {
					background-color: #31b32c;
					top: 100px;
					border-radius: 40%;
					-webkit-transform: rotate(90deg) scale(1.4);
					transform: rotate(90deg) scale(1.4);
				}

				60% {
					background-color: #1b8df6;
					top: 200px;
					border-radius: 60%;
					-webkit-transform: scale(.4) translateX(300);
					transform: scale(.4) translateX(300);
				}
				80% {
					background-color: #ba38d5;
					top: 300px;
					border-radius: 80%;
					-webkit-transform: rotate(-90deg) scale(1.4);
					transform: rotate(-90deg) scale(1.4);
				}
				100% {
					background-color: #2bbada;
					top: 400px;
					border-radius: 100%;
				}
			}

			@-webkit-keyframes Demo1 {
				form {
					background-color: #df5891;
					-webkit-transform: translateX(50px);
					transform: translateX(150px);
					border-radius: 25%;
					top: 100px;
				}

				50% {
					-webkit-transform: scale(2);
					transform: scale(2);
					-webkit-transform: translateX(350px);
					transform: translateX(150px);
					background-color: #642eb1;
					border-radius: 35%;
					top: 200px;
				}
				75% {
					-webkit-transform: scale(2);
					transform: scale(2.5);
					-webkit-transform: translateX(150px);
					transform: translateX(150px);
					background-color: #642eb1;
					border-radius: 55%;
					top: 400px;
				}

				to {
					background-color: #05823b;
					-webkit-transform: translateX(250px);
					transform: translateX(250px);
					border-radius: 75%;
					top: 600px;
				}
			}

			@keyframes Demo1 {
				form {
					background-color: #df5891;
					-webkit-transform: translateX(50px);
					transform: translateX(150px);
					border-radius: 25%;
					top: 100px;
				}

				50% {
					-webkit-transform: scale(2);
					transform: scale(2);
					-webkit-transform: translateX(350px);
					transform: translateX(150px);
					background-color: #642eb1;
					border-radius: 35%;
					top: 200px;
				}
				75% {
					-webkit-transform: scale(2);
					transform: scale(2.5);
					-webkit-transform: translateX(150px);
					transform: translateX(150px);
					background-color: #642eb1;
					border-radius: 55%;
					top: 400px;
				}

				to {
					background-color: #05823b;
					-webkit-transform: translateX(250px);
					transform: translateX(250px);
					border-radius: 75%;
					top: 600px;
				}
			}
		</style>
	</head>
	<body>
		<div class="demo">简易动画效果</div>
		<div class="demo1">啦啦德玛西亚</div>
	</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

crper

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值