Skip to content
Advertisement

Div with sprite-animation doesn’t change properly during window.resize event

I am trying to imitate 3d-model rotation with a sprite sheet. I found a perfect example on Codepen, but it was not responsive.

What I tried to do is to write divs, containers and spritesize (in script) in vw, and then it is being checked in the window.resize event. It does work, but unfortunately not DURING window resize.

I put my snippet and three pictures in the post —

  1. I opened website and everything is perfect – image
  2. I started to change the size of my browser window and as you can see something is wrong – image
  3. Now I tried to “rotate” the “model” with resized window and all is fine again – image

JavaScript
JavaScript
JavaScript

Advertisement

Answer

The issue is because you’re referencing t in the window.resize event handler, yet that variable has been defined in a different scope, and is not accessible from that location.

To fix this issue you can replace t in that function with the spriteslider variable, as that’s what t is expected to contain. Try this:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement