通过JS控制CSS实现连帧动画
2012-06-20 18:38
615 查看
![](http://my.csdn.net/uploads/201206/21/1340236327_1203.png)
网页类Web游戏开发中常常需要实现连帧的动画效果,但是又不方便通过GIF图片去替代,比如动物的移动就是一种。
下面代码是一个简单的连帧动画的Demo。
<html> <head> <meta charset="UTF-8"> <title>动画demo</title> <style type="text/css" rel="stylesheet"> body div{ background-image:url(image/donghua.png); background-repeat:no-repeat} .step1{background-position:0px 0px;} .step2{background-position:-111px 0px;} .step3{background-position:-222px 0px;} .step4{background-position:-333px 0px;} .step5{background-position:-444px 0px;} .step6{background-position:-555px 0px;} .step7{background-position:-666px 0px;} .step8{background-position:-777px 0px;} </style> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript"> var n=0; //持续设置图片旋转角度,使其显示旋转动画 setInterval(function(){ $("#donghua").css({"position":"relative","left":-n+"px","background-position":n+"px 0px"}); n=(n>-777)?n-111:-111; },300); </script> </head> <body style="background-color:black;"> <div class="step1" style="width:111px;height:57px;"></div> <div class="step2" style="width:111px;height:57px;"></div> <div class="step3" style="width:111px;height:57px;"></div> <div class="step4" style="width:111px;height:57px;"></div> <div class="step5" style="width:111px;height:57px;"></div> <div class="step6" style="width:111px;height:57px;"></div> <div class="step7" style="width:111px;height:57px;"></div> <div class="step8" style="width:111px;height:57px;"></div> <hr color="red"> <div id="donghua" style="width:111px;height:57px;"> </div> </body> </html>
最终效果如图所示:
![](http://my.csdn.net/uploads/201206/20/1340188852_3944.png)
相关文章推荐
- 通过JS控制CSS实现连帧动画
- 通过JS和CSS,实现网页加载中的动画效果
- JS+CSS实现网页加载中的动画效果
- 通过CSS控制图片样式,实现图片弹出效果
- 通过js实现简单的动画效果
- js+css实现文字散开重组动画特效代码分享
- 微信小程序 通过控制CSS实现view隐藏与显示
- JS+CSS实现鼠标经过弹出一个DIV框完整实例(带缓冲动画渐变效果)
- 简单说 通过JS控制CSS的各种方式(上)
- js、jquery和css 3中的动画实现效果
- 控制网页文件大小通过精简CSS实现
- 详解微信小程序 通过控制CSS实现view隐藏与显示
- CSS教程:控制网页文件大小通过精简CSS实现
- 使用js函数实现的通过输入框中数据的长度来控制光标聚焦位置
- 通过JS+CSS实现简单的遮罩层
- google曾经的首页小图标,JS+CSS实现的动画效果
- HTML+CSS+JS实现缓冲动画
- 用js+css实现帧动画播放的功能
- 原生JS实现CSS动画效果