Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Title of the Document</title> <style> img { position: relative; cursor: pointer; width: 300px; height: 200px; } </style> </head> <body> <img id="imgId" src="https://ru.w3docs.com/uploads/media/default/0001/05/2c669e35c4c5867094de4bed65034d0cac696df5.png" alt="JS" /> <script> imgId.onclick = function() { let start = Date.now(); let timer = setInterval(function() { let timePassed = Date.now() - start; imgId.style.left = timePassed / 10 + 'px'; if(timePassed > 3000) clearInterval(timer); }, 20); } </script> </body> </html>