CSS动画

CSS动画-animation

动画是使元素从一种样式逐渐变化为另一种样式的效果。
使用百分比来规定变化发生的时间,或用关键词 “from” 和 “to”,等同于 0% 和 100%。0% 是动画的开始,100% 是动画的完成。为了得到最佳的浏览器支持,应始终定义 0% 和 100% 选择器。

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		/* 1. 创建动画 */
    	@keyframes myanimation1 {
			
			from { background-color: green; }
			to { background-color: red; }

    	}
    	/* 2. 使用 animation 绑定动画  */
    	div.div1 {
    		width: 400px;
    		height: 400px;
    		background-color: yellow;
    		animation: myanimation1 2S;
    	}
		@keyframes mymove
		{
			from { left: 0px; }
			to { left: 200px; }
			/* 等价于 */
/* 			0% { left: 0px; }
			100% { left: 200px; } */
		}
		div.div2 {
    		width: 400px;
    		height: 400px;
    		position:relative;
    		background-color: green;
    		animation: mymove 2S infinite;
    	}
	</style>
</head>
<body>
	<div class="div1"></div>
	<hr>
	<div class="div2"></div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值