+ 1
Why is addEventListner not working?
Hey guys, so I saw a youtube video on 3D animation and then tried to do the same. This is my code. https://anothervatsalsharma.github.io/first3DAnimation/ The above is the link to the GitHub website where the same code works perfectly. It works perfectly in browser but when I type it in the code playground, it doesn't work. Please help. Heads up : I've used mousemove so for best experience view the above code in a laptop/pc. https://code.sololearn.com/Wa3A7a15A25A/?ref=app
4 Respuestas
+ 2
Put your code in the JS tab inside a window.onload
window.onload = ()=>{
... code here ...
}
or inside a script tag at the bottom of the body. (between lines 28 and 29)
+ 2
ChaoticDawg Now it works perfectly..... Can you please explain why window.onload was necessary.
Was the js code perhaps being read before the entire html was loaded so an error was being caused?
+ 2
The CSS tab and JS tab in the playground are injected into the head of the Html page prior to the DOM being constructed which is why those objects were null as they didn't exist.
+ 1
Ohk thanks