2010-09-09 122 views
0

我正在尋找一個簡單的腳本來移動JavaScript中的圖像。 Google搜索結果中的代碼示例不適合我。javascript:點擊按鈕時移動圖像

請幫忙。

+1

你是什麼意思的「移動圖像」?移動它在哪裏? – Pointy 2010-09-09 20:12:22

+0

「移動圖像」的含義是什麼?這可能是任何事情。 – RoToRa 2010-09-09 20:13:53

回答

3

要直接回答您的問題,此腳本會將您的問題的下方42像素和42像素的圖像移到絕對定位的父級的右側(前提是圖像尚未處於該位置)。

var img = document.getElementById("IDImage"); 
img.style.position = "absolute"; // You should style this with CSS, not this script 
img.style.top = 42 + "px"; 
img.style.left = 42 + "px"; 
+0

謝謝你palswim !!!這是非常有用的,並立即工作。你是一個偉大的SO公民。 – 2010-09-12 21:42:59