import React, { useRef } from 'react'; import { Wrapper, Layer } from './style'; import { IParallax, IParallaxLayer } from './types'; export const Parallax = function({ children, ...rest }: IParallax) { const ref: any = useRef(); return ( { var x = e.clientX, y = e.clientY, layers = ref.current.querySelectorAll('.parallax-layer'); for (let j = 0; j < layers.length; j++) { var deep = layers[j].getAttribute('data-parallax-deep'), disallow = layers[j].getAttribute('data-parallax-disallow'), itemX = disallow && disallow === 'x' ? 0 : x / deep, itemY = disallow && disallow === 'y' ? 0 : y / deep; if (disallow && disallow === 'both') return; layers[j].style.transform = 'translateX(' + itemX + '%) translateY(' + itemY + '%)'; } }} > {children} ); }; export const ParallaxLayer = function({ children, deep, disabledDirection, ...rest }: IParallaxLayer) { return ( {children} ); }; Parallax.Layer = ParallaxLayer; Parallax.defaultProps = { height: 500, }; export default Parallax;