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

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

(x) 秒后移動圖像

(x) 秒后移動圖像

MMTTMM 2023-08-05 21:00:14
我試圖在 5 秒后將圖像移動到網(wǎng)頁上的隨機(jī)位置,到目前為止我有這個:var image = document.getElementById('image');var position = 0;var timing = setInterval(timing, 5000);image.style.position = 'relative';image.onclick=function move(direction){  var top = Math.floor(Math.random()*75);  var left = Math.floor(Math.random()*75);  var right = Math.floor(Math.random()*75);  var bottom = Math.floor(Math.random()*75);  image.style.top = top + 'px';  image.style.left = left + 'px';  image.style.right = right + 'px';  image.style.bottom = bottom + 'px';}如何讓它在 5 秒后移動?
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個贊

創(chuàng)建一個moveImage函數(shù):

function moveImage(){

  var top = Math.floor(Math.random()*75);

  var left = Math.floor(Math.random()*75);

  var right = Math.floor(Math.random()*75);

  var bottom = Math.floor(Math.random()*75);

  image.style.top = top + 'px';

  image.style.left = left + 'px';

  image.style.right = right + 'px';

  image.style.bottom = bottom + 'px';

}

更新 onClick 以使用新函數(shù):

image.addEventListener('click', moveImage);


更新間隔以使用新函數(shù):

var timing = setInterval(moveImage, 5000);


整個東西:


var image = document.getElementById('image');

image.style.position = 'relative';


function moveImage(){

  var top = Math.floor(Math.random()*75);

  var left = Math.floor(Math.random()*75);

  var right = Math.floor(Math.random()*75);

  var bottom = Math.floor(Math.random()*75);

  image.style.top = top + 'px';

  image.style.left = left + 'px';

  image.style.right = right + 'px';

  image.style.bottom = bottom + 'px';

};


image.addEventListener('click', moveImage);

var timing = setInterval(moveImage, 5000);


查看完整回答
反對 回復(fù) 2023-08-05
  • 1 回答
  • 0 關(guān)注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號