locomotivemtl / locomotive-scroll

šŸ›¤ Detection of elements in viewport & smooth scrolling with parallax.
https://locomotivemtl.github.io/locomotive-scroll
MIT License
7.84k stars 1.12k forks source link

Uncaught TypeError: Cannot read properties of undefined (reading 'inView') #431

Closed SoulDesignerTom closed 2 years ago

SoulDesignerTom commented 2 years ago

Hello šŸ‘‹

Describe the bug As it states - locomotivescroll is working but i got this strange error and i'm not sure what it's aiming for. I've got code like:

const scroll = new LocomotiveScroll({
        el: document.querySelector('body'),
        smooth: true
    });

    scroll.on('scroll', (position) => {
      if ((position.scroll.y) > 50) {
        document.querySelector('.top-header').classList.add('scrolled');
      } else {
        document.querySelector('.top-header').classList.remove('scrolled');
      }
      if($('.number-h').hasClass('is-inview')) {
        demo.start();
      }
    });

The issue is that because of this error the paremeters below doesn't work .top-header doesn't got his class when scrolling and demo.start() isn't working.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://tomb.pl/projects/spotless-water/
  2. Scroll down
  3. See that top-header doesn't get it's class and change the background (like it was before)

Expected behavior Top-header should shrink down a bit (based on changed class).

Desktop (please complete the following information):

Thank you šŸ‘Š

SoulDesignerTom commented 2 years ago

Ok - i've found the reason - in .top-header - i've put element with data-scroll - and it wasn't working because .top-header wasn't a data-scroll-section