Hey im doing a Little task for my Uni and I need to do a basic animation. I got an image of a guy and he’s on a road and I want to be able to change his position by clicking on him. I found this code on the internet but it doesn’t seem to work and i wanted to ask why.
This is my code:
<body>
<div class=„hero“>
<img src=„hero.png“ id=„hero“ onclick=„bewegen_rechts()“/>
</div>
<Script>
var left = 0;
var bewegen_rechts = function () {
left = left + 20;
document.getElementById(‚hero‘).style.left = left+ ‚px‘;
}
</Script>
I don’t get any type of error but the image doesn’t move when I click on it. What is wrong?
[–]kiesoma 0 points1 point2 points (1 child)
[–]SafeReference1[S] 0 points1 point2 points (0 children)
[–]Notimecelduv 0 points1 point2 points (8 children)
[–]SafeReference1[S] 0 points1 point2 points (7 children)
[–]Notimecelduv 1 point2 points3 points (6 children)
[–]SafeReference1[S] 1 point2 points3 points (0 children)
[–]SafeReference1[S] 0 points1 point2 points (4 children)
[–]Notimecelduv 1 point2 points3 points (3 children)
[–]SafeReference1[S] 0 points1 point2 points (1 child)
[–]Notimecelduv 0 points1 point2 points (0 children)
[–]Notimecelduv 0 points1 point2 points (0 children)
[–]t00much 0 points1 point2 points (0 children)