UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

28 lines (27 loc) 737 B
import { useRef as s, useState as a, useEffect as l } from "react"; const d = (t) => { const e = window.innerHeight, n = t.top + t.height / 2, o = e * 0.4, i = e * 0.6; if (n <= i) return 1; { const c = Math.min( Math.abs(n - o), Math.abs(n - i) ), r = e / 4; return Math.max(0, 1 - c / r); } }; function h() { const t = s(null), [e, n] = a(1); return l(() => { const o = () => { const i = t.current.getBoundingClientRect(); n(d(i)); }; return t && (window.addEventListener("scroll", o), o()), () => window.removeEventListener("scroll", o); }, [t]), { ref: t, opacity: e }; } export { h as useScrollFadeTransition }; //# sourceMappingURL=useScrollFadeTransition.js.map