Last active
October 21, 2023 08:59
-
-
Save roydukkey/5c914ab76ee01bdd0f98ea01623d2920 to your computer and use it in GitHub Desktop.
Typedef for parallax.js until they finally publish one. Give my your improvements. React parallax example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'parallax-js' { | |
export default class Parallax { | |
private inputElement?: string | HTMLElement | null; | |
private calibrateX?: boolean; | |
private calibrateY?: boolean; | |
private invertX?: boolean; | |
private invertY?: boolean; | |
private limitX?: number | false; | |
private limitY?: number | false; | |
private scalarX?: number; | |
private scalarY?: number; | |
private frictionX?: number; | |
private frictionY?: number; | |
private originX?: number; | |
private originY?: number; | |
public precision?: number; | |
public relativeInput?: boolean; | |
public clipRelativeInput?: boolean; | |
public pointerEvents?: boolean; | |
public hoverOnly?: boolean; | |
public selector?: string | null; | |
public onReady?: () => void; | |
constructor(element: HTMLElement, options?: IParallaxOptions); | |
public enable(): void; | |
public disable(): void; | |
public destroy(): void; | |
public version(): void; | |
public setInputElement(element: string | HTMLElement | null): void; | |
public calibrate(x: boolean, y: boolean): void; | |
public invert(x: boolean, y: boolean): void; | |
public limit(x: number | false, y: number | false): void; | |
public scalar(x: number, y: number): void; | |
public friction(x: number, y: number): void; | |
public origin(x: number, y: number): void; | |
} | |
export interface IParallaxOptions { | |
precision?: number; | |
relativeInput?: boolean; | |
clipRelativeInput?: boolean; | |
hoverOnly?: boolean; | |
inputElement?: string | HTMLElement | null; | |
pointerEvents?: boolean; | |
calibrateX?: boolean; | |
calibrateY?: boolean; | |
invertX?: boolean; | |
invertY?: boolean; | |
limitX?: number | false; | |
limitY?: number | false; | |
scalarX?: number; | |
scalarY?: number; | |
frictionX?: number; | |
frictionY?: number; | |
originX?: number; | |
originY?: number; | |
selector?: string | null; | |
onReady?: () => void; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Parallax from 'parallax-js'; | |
import React, { useEffect, useState } from 'react'; | |
export default function Index (): JSX.Element { | |
const [parallaxScene, setParallaxScene] = useState<Parallax>(); | |
// componentDidMount | |
useEffect(() => { | |
const sceneNode = document.getElementById('parallax'); | |
if (sceneNode) { | |
setParallaxScene(new Parallax(sceneNode)); | |
} | |
// componentWillUnmount | |
return (): void => { | |
parallaxScene?.disable(); | |
}; | |
}, []); | |
return <div id="parallax" />; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment