-3
A
回答
1
您需要使用圖層...僅繪製正在移動的部分。 有一個在該地址一個偉大的教程: http://arc.id.au/CanvasLayers.html
從該網站引用:
傳統的動畫的技術是使用透明層覆蓋在背景圖像的堆疊,與物品進行動畫每個都在一個單獨的圖層上繪製。只有在每個框架上更改的圖層都重繪,其他圖層保持不變。圖形引擎可以將要暴露的區域從底層重新繪製出來,而不需要用戶代碼。
0
一個(有點)簡單的方法是使用兩個畫布。
<帆布ID = 「foregroundCanvas」 > < /帆布>
<帆布ID = 「backgroundCanvas」 > < /帆布>
這裏是W3Schools的一個偉大的教程:
http://www.w3schools.com/canvas/canvas_clock_start.asp
的以下是鏈接中的代碼。
<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width="400" height="400"
style="background-color:#333">
</canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var radius = canvas.height/2;
ctx.translate(radius, radius);
radius = radius * 0.90
setInterval(drawClock, 1000);
function drawClock() {
drawFace(ctx, radius);
drawNumbers(ctx, radius);
drawTime(ctx, radius);
}
function drawFace(ctx, radius) {
var grad;
ctx.beginPath();
ctx.arc(0, 0, radius, 0, 2*Math.PI);
ctx.fillStyle = 'white';
ctx.fill();
grad = ctx.createRadialGradient(0,0,radius*0.95, 0,0,radius*1.05);
grad.addColorStop(0, '#333');
grad.addColorStop(0.5, 'white');
grad.addColorStop(1, '#333');
ctx.strokeStyle = grad;
ctx.lineWidth = radius*0.1;
ctx.stroke();
ctx.beginPath();
ctx.arc(0, 0, radius*0.1, 0, 2*Math.PI);
ctx.fillStyle = '#333';
ctx.fill();
}
function drawNumbers(ctx, radius) {
var ang;
var num;
ctx.font = radius*0.15 + "px arial";
ctx.textBaseline="middle";
ctx.textAlign="center";
for(num = 1; num < 13; num++){
ang = num * Math.PI/6;
ctx.rotate(ang);
ctx.translate(0, -radius*0.85);
ctx.rotate(-ang);
ctx.fillText(num.toString(), 0, 0);
ctx.rotate(ang);
ctx.translate(0, radius*0.85);
ctx.rotate(-ang);
}
}
function drawTime(ctx, radius){
var now = new Date();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
//hour
hour=hour%12;
hour=(hour*Math.PI/6)+
(minute*Math.PI/(6*60))+
(second*Math.PI/(360*60));
drawHand(ctx, hour, radius*0.5, radius*0.07);
//minute
minute=(minute*Math.PI/30)+(second*Math.PI/(30*60));
drawHand(ctx, minute, radius*0.8, radius*0.07);
// second
second=(second*Math.PI/30);
drawHand(ctx, second, radius*0.9, radius*0.02);
}
function drawHand(ctx, pos, length, width) {
ctx.beginPath();
ctx.lineWidth = width;
ctx.lineCap = "round";
ctx.moveTo(0,0);
ctx.rotate(pos);
ctx.lineTo(0, -length);
ctx.stroke();
ctx.rotate(-pos);
}
</script>
</body>
</html>
相關問題
- 1. Html5畫布動畫
- 2. 動態HTML5畫布動畫
- 3. 動畫GIF在HTML5畫布
- 4. HTML5畫布動畫問題
- 5. html5 - 拖動畫布
- 6. html5畫布滾動
- 7. HTML5畫布,文字和JavaScript
- 8. Javascript/HTML5畫布重繪
- 9. 動畫在HTML5畫布中很慢
- 10. 閃存CC HTML5畫布播放動畫
- 11. 動畫選項HTML5畫布/ CSS3/jQuery
- 12. html5畫布 - 按路徑動畫對象
- 13. 與HTML5畫布等待動畫
- 14. html5動畫畫布已繪製元素
- 15. 將多個HTML5畫布動畫
- 16. HTML5畫布,動畫和封閉庫
- 17. 如何在HTML5畫布中動畫樹
- 18. HTML5畫布:如何動畫上下文?
- 19. HTML5畫布中的流暢動畫
- 20. 用畫布在HTML5中逐幀動畫
- 21. 使得HTML5畫布互動
- 22. Html5畫布文字互動?
- 23. HTML5畫布浮動圈
- 24. 「googlemaps」拖動html5畫布
- 25. 移動HTML5畫布元素
- 26. stage.toJSON()動能JS HTML5畫布
- 27. HTML5動態創建畫布
- 28. HTML5畫布線條畫
- 29. onmouse畫布HTML5
- 30. HTML5畫布,GUI
得到任何代碼顯示? – alex 2012-04-16 00:23:26
然後,請勿將手錶照片放在畫布上,將畫布放在畫布上。 – david 2012-04-16 00:30:49
我沒有代碼,我只是有想法,我無法實現它,真的需要幫助。 – 2012-04-16 06:33:56