用jS 做逐帧动画

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
    <style>
        #anidem{
            width:320px;
            height:378px; 
            background:url(img/imgs.png) no-repeat
        }
    </style>
</head>
    
<body>
    <div id="anidem"></div>
    <script>
        

    var anidem = document.getElementById("anidem");
        
    
        
    var count=0
    var counts= 0
    var  tsid = 0 
    setInterval(function()
                {

        anidem.style.backgroundPosition = ((-320*count)+"px "+(counts)+"px");

        count++;
        if(count>=7)
        {count=0
        counts = -430*tsid;
        tsid++;
         if(tsid>=6){ tsid=0;}
                    }
    },100)
    </script>
</body>
</html>

 

图片    对setInterval用js  函数来做。其中要注意anidem.style.backgroundPosition = ((-320*count)+"px ")   px后面的空格很重要。
 
 
 
posted @ 2017-03-15 12:07  连月无暇  阅读(4415)  评论(0编辑  收藏  举报