Created
November 12, 2021 16:18
-
-
Save paprikka/b519a8f5c4ba020900ffc8aa9baa27b1 to your computer and use it in GitHub Desktop.
Rainbow bg from https://potato.horse
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 { useEffect } from 'react' | |
export const useRainbowBg = () => | |
useEffect(() => { | |
const cb = () => { | |
const viewportHeight = window.innerHeight | |
const contentHeight = document.body.getBoundingClientRect().height | |
const viewportsPerRotation = Math.min( | |
3, | |
contentHeight / viewportHeight | |
) | |
const from = 51 | |
const to = 219 | |
const progress = | |
window.scrollY / (viewportHeight * viewportsPerRotation) | |
const h = from + (to - from) * progress | |
document.body.style.backgroundColor = `hsl(${h}deg 100% 50%)` | |
} | |
window.addEventListener('scroll', cb, { passive: true }) | |
return () => window.removeEventListener('scroll', cb) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment