每天一個JavaScript執行個體-canvas定時器動態更新一個線條,javascript-canvas

來源:互聯網
上載者:User

每天一個JavaScript執行個體-canvas定時器動態更新一個線條,javascript-canvas

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>每天一個JavaScript執行個體-canvas定時器動態更新一個線條</title><style></style><script>window.onload = function(){var array1 = [[100,100],[150,50],[200,185],[250,185],[300,250],[350,100],[400,250],[450,100],[500,20],[550,80],[600,120]];var array2 = [[100,100],[150,150],[200,135],[250,285],[300,150],[350,150],[400,280],[450,100],[500,120],[550,80],[600,190]];var array3 = [[100,200],[150,100],[200,35],[250,185],[300,10],[350,15],[400,80],[450,100],[500,120],[550,80],[600,120]];var imgcanvas = document.getElementById("imgcanvas");if(imgcanvas.getContext){var ctx = imgcanvas.getContext('2d');//矩形包圍線條表徵圖ctx.strokeRect(0,0,600,300);//第一條線條ctx.beginPath();ctx.moveTo(0,100);for(var i=0;i<array1.length;i++){ctx.lineTo(array1[i][0],array1[i][1]);}ctx.stroke();}setTimeout(function(){ctx.strokeStyle="#f00";//第二條線ctx.beginPath();ctx.moveTo(0,100);for(var i=0;i<array2.length;i++){ctx.lineTo(array2[i][0],array2[i][1]);}ctx.stroke();//第二次延遲setTimeout(function(){ctx.strokeStyle = "0f0";ctx.fillStyle="rgba(255,255,0,.1)";//第三條線ctx.beginPath();ctx.moveTo(0,100);for(var i=0;i<array3.length;i++){ctx.lineTo(array3[i][0],array3[i][1]);}ctx.stroke();},5000);},5000);}</script></head><body><canvas width="650" height="350" id="imgcanvas"><p>img</p></canvas></body></html>


javascript在canvas中定義一個用來顯示的類,產生執行個體之後,怎來對其執行相應的滑鼠事件

這個只能給canvas添加事件,然後判斷點擊的時候的位置是否和矩形重疊
 
javascript 的定時器中調用動態語句

那肯定是不行的了,因為你把資料放到js中,和你直接處理,我想花費的時間應該差不多,而且你的資料量那麼大,那一定是很慢的。

用ajax處理是最好的方法了。

每次調用少量的資料,多次處理。

思路是另外做一個產生xml的頁面,把你的資料產生xml格式,通過傳遞的參數(這可以做成類似分頁取資料的方式)來分批取。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.