JS 小鸟飞

<!DOCTYPE html>


<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script>
        
        onload = function () {
            var timer;
            document.getElementById('btnStart').onclick = function () {
                var i=0;
                timer = setInterval(function(){
                    i++;
                    if (i>4) {
                        i = 1;
                    }
                    document.getElementById('img').src='bird'+i+'.png';
                },1000);
                
            };


            document.getElementById('btnStop').onclick = function () {
                clearInterval(timer);
            }
            
        }
    </script>
</head>
<body>
    <img src="" id="img"/><br />
    <input type="button" name="name" value="开始飞" id="btnStart" />
    <input type="button" name="name" value="停止飞" id="btnStop" />
</body>
</html>

猜你喜欢

转载自blog.csdn.net/dxm809/article/details/80248129
今日推荐