开发者

javascript: move image upon button click

开发者 https://www.devze.com 2023-01-15 06:58 出处:网络
I am looking for a simple script to move an image in JavaScript. Code examp开发者_高级运维les from Google search results are not working for me.

I am looking for a simple script to move an image in JavaScript. Code examp开发者_高级运维les from Google search results are not working for me.

Please help.


To directly answer your question, this script will move an image 42 pixels below and 42 pixels to the right of your absolutely-positioned parent (provided that the image was not already in that position).

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

精彩评论

暂无评论...
验证码 换一张
取 消