jQuery/CSS3实现小鸟飞翔动画

自从有了HTML5和CSS3,大家在实现网页动画方面方便多了!上篇我们介绍了圆盘抽奖动画HTML5 Canvas圆盘抽奖应用DEMO演示
这篇我们将使用CSS3的@keyframes规则实现小鸟飞翔的动画!先看下效果:
jQuery/CSS3实现小鸟飞翔动画

CSS3 动画
当您在@keyframes 中创建动画时,请把它捆绑到某个选择器,否则不会产生动画效果。
通过规定至少以下两项 CSS3 动画属性,即可将动画绑定到选择器:规定动画的名称,规定动画的时长,动画源码如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery/CSS3实现小鸟飞翔动画DEMO演示</title>
<script src="http://cdn.bootcss.com/jquery/3.0.0-beta1/jquery.js"></script>
<style type="text/css">
*{margin: 0;padding: 0;}
.box{width: 564px;height: 170px;}
.box div{
	width: 141px;height: 85px;float: left;
	margin-top: 150px;
	margin-left: 50px;
	background:url(images/bird1.png);/* 用于Firefox 可无视 */
	-webkit-animation: myFrist 1s linear infinite;
	-moz-animation: myFrist 1s linear infinite;
	-o-animation: myFrist 1s linear infinite;
	animation: myFrist 1s linear infinite;
}
@-webkit-keyframes myFrist{
	0%    {background:url(images/bird1.png);background-size: 100% 100%}
	12.5% {background:url(images/bird2.png);background-size: 100% 100%}
	25%   {background:url(images/bird3.png);background-size: 100% 100%}
	37.5% {background:url(images/bird4.png);background-size: 100% 100%}
	50%   {background:url(images/bird5.png);background-size: 100% 100%}
	65.7% {background:url(images/bird6.png);background-size: 100% 100%}
	75%   {background:url(images/bird7.png);background-size: 100% 100%}
	87.5% {background:url(images/bird8.png);background-size: 100% 100%}
	100%  {background:url(images/bird1.png);background-size: 100% 100%}
}
@-moz-keyframes myFrist{
	0%    {background:url(images/bird1.png);background-size: 100% 100%}
	12.5% {background:url(images/bird2.png);background-size: 100% 100%}
	25%   {background:url(images/bird3.png);background-size: 100% 100%}
	37.5% {background:url(images/bird4.png);background-size: 100% 100%}
	50%   {background:url(images/bird5.png);background-size: 100% 100%}
	65.7% {background:url(images/bird6.png);background-size: 100% 100%}
	75%   {background:url(images/bird7.png);background-size: 100% 100%}
	87.5% {background:url(images/bird8.png);background-size: 100% 100%}
	100%  {background:url(images/bird1.png);background-size: 100% 100%}
}
@-o-keyframes myFrist{
	0%    {background:url(images/bird1.png);background-size: 100% 100%}
	12.5% {background:url(images/bird2.png);background-size: 100% 100%}
	25%   {background:url(images/bird3.png);background-size: 100% 100%}
	37.5% {background:url(images/bird4.png);background-size: 100% 100%}
	50%   {background:url(images/bird5.png);background-size: 100% 100%}
	65.7% {background:url(images/bird6.png);background-size: 100% 100%}
	75%   {background:url(images/bird7.png);background-size: 100% 100%}
	87.5% {background:url(images/bird8.png);background-size: 100% 100%}
	100%  {background:url(images/bird1.png);background-size: 100% 100%}
}
@keyframes myFrist{
	0%    {background:url(images/bird1.png);background-size: 100% 100%}
	12.5% {background:url(images/bird2.png);background-size: 100% 100%}
	25%   {background:url(images/bird3.png);background-size: 100% 100%}
	37.5% {background:url(images/bird4.png);background-size: 100% 100%}
	50%   {background:url(images/bird5.png);background-size: 100% 100%}
	65.7% {background:url(images/bird6.png);background-size: 100% 100%}
	75%   {background:url(images/bird7.png);background-size: 100% 100%}
	87.5% {background:url(images/bird8.png);background-size: 100% 100%}
	100%  {background:url(images/bird1.png);background-size: 100% 100%}
}
</style>
</head>
<body>
<div class="box"><div></div></div>
<script type="text/javascript">
var timer = setInterval(function(){
	$(".box > div").animate({
		'marginLeft': 1000,
	},{queue:true, duration:5000,complete:function a(){
		 $(".box > div").css('transform','rotateY(180deg)');
	}}).animate({
		'marginLeft': 50,
	},5000,function(){
		 $(".box > div").css('transform','rotateY(0deg)');
	});
},1000);
</script>
</body>
</html>

版权声明:本文为博主原创文章,未经博主允许不得转载。资源在我的qq群里!

jQuery/CSS3实现小鸟飞翔动画

: » jQuery/CSS3实现小鸟飞翔动画

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/251135.html

(0)
上一篇 2022年5月2日
下一篇 2022年5月2日

相关推荐

发表回复

登录后才能评论