Here is my code that makes an image move to the right. I have searched how to call and execute functions but I don't understand they.
I know how to execute it in HTML but not in javascript. I want to execute it when I load the page all the time.
<input type="button" value="Start" onclick="moveRight();" />
I have seen this code but I can't get it to work with my code.
window["functionName"](arguments);
like what I'm supposed to write in the brackets for example.
<script>
var imgObj = null;
var animate ;
function init(){
imgObj = document.getElementById('myImage');
imgObj.style.position= 'relative';
imgObj.style.left = '0px';
}
function moveRight(){
imgObj.style.left = parseInt(imgObj.style.left) + 11 + 'px';
animate = setTimeout(moveRight,22); // call moveRight in 20msec
}
<body>
<form>
<img id="myImage" src="myimage.jpg" />
<p>Click the buttons below to handle animation</p>
<input type="button" value="Start" onclick="moveRight();" />
<input type="button" value="Start" onclick="moveLeft();" />
<input type="button" value="Stop" onclick="stop();" />
</form>