Appearance
useParallax
Create parallax effect easily. It uses useDeviceOrientation and fallback to useMouse if orientation is not supported.
Demo
Usage
tsx
import { useParallax } from '@reause/core'
import { useRef } from 'react'
const container = useRef<HTMLDivElement>(null)
const { tilt, roll, source } = useParallax(container)tsx
<div ref={container} />Type Declarations
ts
export interface UseParallaxOptions extends ConfigurableWindow {
deviceOrientationTiltAdjust?: (i: number) => number;
deviceOrientationRollAdjust?: (i: number) => number;
mouseTiltAdjust?: (i: number) => number;
mouseRollAdjust?: (i: number) => number;
}
export interface UseParallaxReturn {
roll: number;
tilt: number;
source: 'deviceOrientation' | 'mouse';
}
export function useParallax(target: RefObject<HTMLElement | null | undefined>, options?: UseParallaxOptions): UseParallaxReturn