Skip to content

Commit

Permalink
enhancement(Parallax) coding standards eslint fixes materializecss#506
Browse files Browse the repository at this point in the history
  • Loading branch information
gselderslaghs committed Dec 18, 2024
1 parent f2677e3 commit 0fbcf45
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/parallax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class Parallax extends Component<ParallaxOptions> {
private _enabled: boolean;
private _img: HTMLImageElement;
static _parallaxes: Parallax[] = [];
static _handleScrollThrottled: () => any;
static _handleWindowResizeThrottled: () => any;
static _handleScrollThrottled: () => Utils;
static _handleWindowResizeThrottled: () => Utils;

constructor(el: HTMLElement, options: Partial<ParallaxOptions>) {
super(el, options, Parallax);
Expand All @@ -28,7 +28,7 @@ export class Parallax extends Component<ParallaxOptions> {
...Parallax.defaults,
...options
};

this._enabled = window.innerWidth > this.options.responsiveThreshold;
this._img = this.el.querySelector('img');
this._updateParallax();
Expand Down Expand Up @@ -83,8 +83,7 @@ export class Parallax extends Component<ParallaxOptions> {
static _handleWindowResize() {
for (let i = 0; i < Parallax._parallaxes.length; i++) {
const parallaxInstance = Parallax._parallaxes[i];
parallaxInstance._enabled =
window.innerWidth > parallaxInstance.options.responsiveThreshold;
parallaxInstance._enabled = window.innerWidth > parallaxInstance.options.responsiveThreshold;
}
}

Expand Down Expand Up @@ -122,13 +121,13 @@ export class Parallax extends Component<ParallaxOptions> {
const box = el.getBoundingClientRect();
const docElem = document.documentElement;
return {
top: box.top + window.pageYOffset - docElem.clientTop,
left: box.left + window.pageXOffset - docElem.clientLeft
top: box.top + window.scrollY - docElem.clientTop,
left: box.left + window.scrollX - docElem.clientLeft
};
}

_updateParallax() {
const containerHeight = this.el.getBoundingClientRect().height > 0 ? (this.el.parentNode as any).offsetHeight : 500;
const containerHeight = this.el.getBoundingClientRect().height > 0 ? this.el.parentElement.offsetHeight : 500;
const imgHeight = this._img.offsetHeight;
const parallaxDist = imgHeight - containerHeight;
const bottom = this._offset(this.el).top + containerHeight;
Expand Down

0 comments on commit 0fbcf45

Please sign in to comment.