+ 1

How can i make this object move more than ones?

<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <img src=" https://ichef.bbci.co.uk/images/ic/480x270/p05394v7.jpg " width="100" height="100" id="YourObject" style="position:relative;" > <br /> <button onclick="move();">Move</button> </body> </html> //js function move() { var obj = document.getElementById("YourObject"); obj.style.left = 50 + 'px'; }

23rd Aug 2017, 12:43 AM
Reward
Reward - avatar
1 Resposta
+ 20
function move() { var obj = document.getElementById("YourObject"); obj.style.left = Number(obj.style.left.replace(/px$/,""))+50 + 'px'; }
23rd Aug 2017, 7:15 AM
Valen.H. ~
Valen.H. ~ - avatar