css3怎么设置动画时间?

来自:互联网
时间:2019-11-10
阅读:

CSS3可以创建动画,它可以取代许多网页动画图像、Flash 动画和 JavaScript 实现的效果。动画是使元素从一种样式逐渐变化为另一种样式的效果。

css3中可以使用animation-delay属性设置动画开始时间,使用animation-duration属性设置动画完成一个周期所花费时间。

css3设置动画开始时间示例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title></title> 
<style> 
div
{
	width:100px;
	height:100px;
	background:red;
	position:relative;
	animation:mymove 5s infinite;
	animation-delay:2s;

	/*Safari and Chrome*/
	-webkit-animation:mymove 5s infinite;
	-webkit-animation-delay:2s;
}
@keyframes mymove
{
	from {left:0px;}
	to {left:200px;}
}
@-webkit-keyframes mymove /*Safari and Chrome*/
{
	from {left:0px;}
	to {left:200px;}
}
</style>
</head>
<body>
<div></div>
</body>
</html>

animation-delay 属性定义动画什么时候开始。

animation-delay 值单位可以是秒(s)或毫秒(ms)。

语法:

animation-delay: time;

time:可选。定义动画开始前等待的时间,以秒或毫秒计。默认值为0

css3设置动画开始时间示例:

<html><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title></title> 
<style> 
div
{
	width:100px;
	height:100px;
	background:red;
	position:relative;
	animation:mymove infinite;
	animation-duration:2s;

	/* Safari and Chrome */
	-webkit-animation:mymove infinite;
	-webkit-animation-duration:2s;
}
@keyframes mymove
{
	from {top:0px;}
	to {top:200px;}
}
@-webkit-keyframes mymove /* Safari and Chrome */
{
	from {top:0px;}
	to {top:200px;}
}
</style>
</head>
<body>
<p><strong>注意:</strong>  animation-duration属性不兼容 Internet Explorer 9 以及更早版本的浏览器.</p>
<div></div>
<p><b>注意:</b> 要指定动画属性。否则时间若是0,动画不会进行。</p>
</body>
</html>

animation-duration属性定义动画完成一个周期需要多少秒或毫秒。

语法:

animation-duration: time;

time:指定动画播放完成花费的时间。默认值为 0,意味着没有动画效果。

返回顶部
顶部