第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在 JavaScript 中制作修改后的計(jì)數(shù)器動(dòng)畫(huà)?

如何在 JavaScript 中制作修改后的計(jì)數(shù)器動(dòng)畫(huà)?

森林海 2023-08-24 21:02:19
我需要?jiǎng)?chuàng)建一個(gè)顯示兩個(gè)按鈕的網(wǎng)頁(yè):“開(kāi)始”和“停止”。單擊“開(kāi)始”時(shí),我需要每秒顯示一個(gè)方程。例如:假設(shè)起始數(shù)字為100,那么在動(dòng)畫(huà)中,網(wǎng)頁(yè)首先會(huì)顯示:100 + 1 = 101然后每隔一秒,它應(yīng)該顯示:100 + 2 = 102;  100 + 3 = 103; 100 + 4 = 104;等等...每1秒一次。我已經(jīng)能夠創(chuàng)建計(jì)數(shù)器動(dòng)畫(huà),但是,我對(duì)在此之后如何進(jìn)展感到困惑。到目前為止,這是我的代碼<html><head>  <script>  var counter = 100;  var counterSchedule;  function startCounterAnimation(){    counterSchedule = setInterval(showCounter, 1000);  }  function showCounter(){    counter = counter + 1;    var counterSpan = document.getElementById("counter");    counterSpan.innerHTML = counter;  }  function stopCounterAnimation(){    clearInterval(counterSchedule);  }  </script></head><body>  <button onClick="startCounterAnimation()">Start Animation</button>  <button onClick="stopCounterAnimation()">Stop Animation</button>  <br /><br />  <span id="counter"></span></body></html>任何幫助將不勝感激!
查看完整描述

1 回答

?
慕森王

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個(gè)贊

使用下面的代碼嘗試一下。這就是您要找的嗎?


  var counter = 100;

  var counterSchedule;

  let i = 1;


  function startCounterAnimation(){


    counterSchedule = setInterval(showCounter, 1000);

  }


  function showCounter(){


    counter = counter + 1;

    var counterSpan = document.getElementById("counter");

    counterSpan.innerHTML = `100 + ${i} = ${counter}`;

    i++;

  }


  function stopCounterAnimation(){


    clearInterval(counterSchedule);

  }

<html>

<head>

</head>

<body>

  <button onClick="startCounterAnimation()">Start Animation</button>

  <button onClick="stopCounterAnimation()">Stop Animation</button>


  <br /><br />


  <span id="counter"></span>

</body>

</html>


查看完整回答
反對(duì) 回復(fù) 2023-08-24
  • 1 回答
  • 0 關(guān)注
  • 173 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)