在下面的代碼中,乘以0.002是否有任何特殊用途?爲什麼在這行代碼中乘以0.002:new Date()。getTime()* 0.002;
var time = new Date().getTime() * 0.002;
此代碼摘錄是從here拍攝。我提供以下的整個代碼也:
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(/* function */ callback, /* DOMElement */ element){
window.setTimeout(callback, 1000/60);
};
})();
var canvas, context;
init();
animate();
function init() {
canvas = document.createElement('canvas');
canvas.width = 256;
canvas.height = 256;
context = canvas.getContext('2d');
document.body.appendChild(canvas);
}
function animate() {
requestAnimFrame(animate);
draw();
}
function draw() {
var time = new Date().getTime() * 0.002;
var x = Math.sin(time) * 96 + 128;
var y = Math.cos(time * 0.9) * 96 + 128;
context.fillStyle = 'rgb(245,245,245)';
context.fillRect(0, 0, 255, 255);
context.fillStyle = 'rgb(255,0,0)';
context.beginPath();
context.arc(x, y, 10, 0, Math.PI * 2, true);
context.closePath();
context.fill();
}
我也跟着你的鏈接,並看不出代碼隨處可見但我會繼續說,是的,有一個特殊的目的(只是0.002乘以不是偶然發生的事情)。 – nnnnnn
轉到頁面上的JSFiddle窗口,然後單擊JavaScript。 –
我想它會得到自1970年1月1日以來的半秒數。不能在你的鏈接中找到代碼。 –