dixonandmoe / rellax

Lightweight, vanilla javascript parallax library
https://dixonandmoe.com/rellax/
MIT License
7.06k stars 878 forks source link

Throws an Error on Pages Where Parallax CSS Class Isn't Present #168

Open EmilyChews opened 5 years ago

EmilyChews commented 5 years ago

Hi,

I'm using this wonderful library on a couple of sites and I've noticed it's throws an error in the console if certain pages (i.e. a 404 page) don't have the appropriate CSS class in the HTML to use in the rellax object.

Normally I would wrap the function/object in an if statement so it it would only trigger if a certain CSS class is present.

This doesn't seem to be working though?

Any help would be amazing.

The solution I'm trying is as follows:

var largeScreenParallax = document.getElementsByClassName("parallax-large-screen")[0]

if (largeScreenParallax) {

     // -- PARALLAX - IMAGES
     var largeScreenParallax = new Rellax('.parallax-large-screen', {
        speed: 2,
        center: true,
        wrapper: null,
        round: true,
        vertical: true,
        horizontal: false
    });

} // end of if statement
carlwood commented 5 years ago

Hi @EmilyChews, I can't replicate this one. I copied your code and I'm not seeing an error when my page lacks the appropriate CSS class in the HTML.

Did you manage to fix this? Or is there a code sample on codepen or similar I could look at?