0
我想要2個假貨遊標,我試過這個創建2個遊標。如何隨機移動假光標?
// get the fake cursor by is id
var xyMirror = document.getElementById('fakeCursor');
var xyMirror2 = document.getElementById('fakeCursor2');
// listen for mouse movements
window.onmousemove = function(event) {
// get the user's mouse position
var X = event.clientX;
var Y = event.clientY;
// get the browser window dimensions
windowHeight = window.innerHeight;
windowWidth = window.innerWidth;
// create an inversion of the mouse X, Y position
// subtract mouse X position from window width
// subtract mouse Y position from window height
var fakeX = windowWidth - X;
var fakeY = windowHeight - Y;
// use those numbers to update the fake cursor position
xyMirror.style.top = fakeY+'px';
xyMirror.style.left = fakeX+'px';
xyMirror2.style.top = 10 + fakeY+'px' ;
xyMirror2.style.left = 20 + fakeX+'px';
}
現在他們的運動依賴於原來的光標, 我的問題是 如何才能將他們隨機?
'Math.random'一些事情嗎? 'setInterval'? – evolutionxbox
@evolutionxbox不,我認爲我應該使用類似時間的東西 – parik
當你說「像時間」時,你是什麼意思? – evolutionxbox