<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 盒子自動向右移動,到達最右邊,開始返回移動,再重復 ``` <style> *{ margin:0; padding: 0; } #div{ width: 100px; height:100px; background-color: #f00; position: absolute; /* left:100px; */ } button{ position: relative; top:120px; } </style> <div id="div"></div> <button>點擊開始</button> <button>點擊停止</button> <script> // 邏輯:1.一個元素動起來,其實就是位置的移動 // 2.連續動起來,需要一個定時器的 (有一個開關才行,為了防止多個定時器累積) // 3.需要對移動做條件 (當移動距離大于body寬度或小于0) // 當滿足兩個條件 做相反移動 let buts = document.getElementsByTagName('button'); let div = document.getElementById('div'); let body = document.body; let num = 0; let timer = null; buts[0].onclick = function(){ // 聲明一個變量speed,也就是移動的速度 let speed = 5; if(timer==null){ timer = setInterval(()=>{ num += speed;//移動速度 div.style.left = num+'px';//元素真正移動的核心 // 當移動距離大于body寬度或小于0 if(num>=body.offsetWidth-div.offsetWidth || num<=0){ // 速度變量取反 speed = -speed; } },100); } } buts[1].onclick = function(){ clearInterval(timer); timer=null; } </script> ``` ![](https://img.kancloud.cn/76/ea/76eab1d0774b1f965b84e0a22821c26b_750x312.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看