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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在函數內傳遞參數的問題(setInterval)

在函數內傳遞參數的問題(setInterval)

紅糖糍粑 2021-10-14 10:43:09
這是我的代碼。https://www.jsfiddle.net/tpov743w/我正在嘗試完成多個圓形進度條。這個想法是讓它們動態(tài)工作,通過在需要時添加具有不同百分比值的額外 progressCircle_# 對象。如您所見,進度條加載數據并執(zhí)行動畫,但是當我檢查瀏覽器中的元素時,我注意到無數“ReferenceError: start is not defined”。我需要幫助來克服這個問題。感謝您的任何建議。var progressCircle_1 = {  procent: 89,  startFrom: 0,  incrementBy: 1,  canvasId: 'canvas',  procentId: 'procent',  funct: function() {    var start = setInterval(function() {      draw.call(progressCircle_1)    }, 50);  }}var progressCircle_2 = {  procent: 59,  startFrom: 0,  incrementBy: 1,  canvasId: 'canvas1',  procentId: 'procent1',  funct: function() {    var start = setInterval(function() {      draw.call(progressCircle_2)    }, 50);  }}progressCircle_1.funct();progressCircle_2.funct();function draw() {  (this.startFrom < this.procent) ? this.startFrom++: clearInterval(start);  var getCanvas = document.getElementById(this.canvasId).getContext('2d');  var getNumber = document.getElementById(this.procentId).innerHTML = this.incrementBy++;  getCanvas.beginPath();  getCanvas.arc(250, 250, 100, 0, 0.06283185307179587 * this.startFrom);  getCanvas.lineWidth = '15';  getCanvas.strokeStyle = "white";  getCanvas.lineCap = "round";  getCanvas.stroke();};
查看完整描述

3 回答

?
明月笑刀無情

TA貢獻1828條經驗 獲得超4個贊

只需添加var start在頂部而不是funct函數內部


完整的JS代碼:


var start


var progressCircle_1 = {

  procent:89,

  startFrom:0,

  incrementBy:1,

  canvasId:'canvas',

  procentId:'procent',

  funct: function(){

    start = setInterval(function(){draw.call(progressCircle_1)},50);

  }

}

var progressCircle_2 = {

  procent:59,

  startFrom:0,

  incrementBy:1,

  canvasId:'canvas1',

  procentId:'procent1',

  funct: function(){

    start = setInterval(function(){draw.call(progressCircle_2)},50);

  }

}


progressCircle_1.funct();

progressCircle_2.funct();



function draw(){

  (this.startFrom<this.procent)?this.startFrom++:clearInterval(start);

  var getCanvas = document.getElementById(this.canvasId).getContext('2d');

  var getNumber = document.getElementById(this.procentId).innerHTML=this.incrementBy++;

  getCanvas.beginPath();

  getCanvas.arc(250,250,100,0,0.06283185307179587*this.startFrom);

  getCanvas.lineWidth='15';

  getCanvas.strokeStyle="white";

  getCanvas.lineCap="round";

  getCanvas.stroke();

};



查看完整回答
反對 回復 2021-10-14
  • 3 回答
  • 0 關注
  • 172 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號