funkhaus / lenis-scroll-snap

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

constructor outdated?

hrvstr opened this issue · comments

When I use the plugin as described in the example project I get this error in the console.

[Error] TypeError: undefined is not an object (evaluating 'this.rootElement.getAttribute')

	ScrollSnap (scroll-snap.js:14)
	Modulcode (Lenis.astro:15)

When looking at the code in scroll-snap.js I see that it calls this.lenis.wrapperNode and this.lenis.contentNode which do not seem to be available in recent versions of lenis at least. I replaced them with lenis.options.wrapper and lenis.options.content, which made the error disappear.

  constructor(lenis, { snapType }) {
    this.lenis = lenis;
    this.isHorizontal = this.lenis.direction === "horizontal"; // we can set different value in case we need snap for different axis.
    this.rootElement =
      this.lenis.options.wrapper === window
        ? this.lenis.options.content
        : this.lenis.options.wrapper;
    this.snapType =
      snapType ||
      this.rootElement.getAttribute("scroll-snap-type") ||
      "mandatory";

    this.initElements();
    lenis.on("scroll", this.onScroll);
  }

We actually have two branches. One for the old Lenox version, and one for the new version. Try the other branch and let me know if that works or not. Thanks for trying it out!

Ah sorry, I didn't notice the different branches. I tried the 1.0 branch now and got the same error. In the code, I still see references to this.lenis.wrapper.element for example. Thanks for your great work. I am actually using a custom version now that works pretty well.