html文件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style type="text/css"> .walk_show{ width:120px; height:182px; border:1px solid #333; margin:50px auto 0; overflow:hidden; position:relative; } .walk_show img{ position:absolute; left:0px; top:0px; } </style> <script type="text/javascript"> window.onload = function(){ var oImg = document.getElementById('img01'); var nowleft = 0; function fnMove(){ nowleft -= 120; if(nowleft<-840) { nowleft=0; } oImg.style.left = nowleft + 'px'; } setInterval(fnMove,120); } </script> </head> <body> <p>使用下面这张图片制作关键帧动画</p> <img src="images/walking.png" alt="人物走路"> <div class="walk_show"> <img src="images/walking.png" alt="人物走路" id="img01"> </div> </body> </html>