+ 7
i am trying to create an animation with JS and has a linewith obj.style.left but displays that it cannot read the property style
please i am trying to create an animation with Javascript and has a linewith obj.style.left but displays that it cannot read the property style
4 Réponses
+ 5
how do I stop the animation from executing unless the button is pressed
https://code.sololearn.com/WkdtOeZjB0QP/?ref=app
+ 1
Post your code?
+ 1
<script>
var t= setInterval(gunned,500);
var ini = 0;
//our box element
var bullet = document.getElementById("bullet");
function gunned() {
ini += 1;
bullet.style.left = ini+"px";
}
</script>
^Post your JS script at the bottom of your HTML <body>. Basically, it's loading your script before it loads the HTML, so the element with the ID "bullet" doesn't exist at the time that JS checks. If you put it at the bottom of your HTML, it'll load the HTML first before it loads your script, thus the element "bullet" will exist at that time.
Hope that helps.