Java基础、中级、高级、架构面试资料

jQuery/CSS3实现小鸟飞翔动画

HTML5 herman 4403浏览 0评论
公告:“业余草”微信公众号提供免费CSDN下载服务(只下Java资源),关注业余草微信公众号,添加作者微信:xttblog2,发送下载链接帮助你免费下载!
本博客日IP超过2000,PV 3000 左右,急需赞助商。
极客时间所有课程通过我的二维码购买后返现24元微信红包,请加博主新的微信号:xttblog2,之前的微信号好友位已满,备注:返现
受密码保护的文章请关注“业余草”公众号,回复关键字“0”获得密码
所有面试题(java、前端、数据库、springboot等)一网打尽,请关注文末小程序
视频教程免费领
腾讯云】1核2G5M轻量应用服务器50元首年,高性价比,助您轻松上云

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

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群里!

业余草公众号

最后,欢迎关注我的个人微信公众号:业余草(yyucao)!可加作者微信号:xttblog2。备注:“1”,添加博主微信拉你进微信群。备注错误不会同意好友申请。再次感谢您的关注!后续有精彩内容会第一时间发给您!原创文章投稿请发送至532009913@qq.com邮箱。商务合作也可添加作者微信进行联系!

本文原文出处:业余草: » jQuery/CSS3实现小鸟飞翔动画