用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后面的空格很重要。
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM