Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VanillaTilt.js destroy tilt in divs

Help please.Have an error in console

TypeError: Cannot read properties of undefined (reading ‘destroy’)

  if (window.innerWidth > 991.98) {
     VanillaTilt.init(destroyBox, {
        max: 10,
        speed: 10000
     })
  } else {
     destroyBox.vanillaTilt.destroy();
  }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can’t destroy when never been init. That is the fix. However for an ugly workaround you can

  if (window.innerWidth > 991.98) {
     destroyBox.vanillaTilt || VanillaTilt.init(destroyBox, {
        max: 10,
        speed: 10000
     })
  } else {
     destroyBox.vanillaTilt && destroyBox.vanillaTilt.destroy();
  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading