Download NetflixClone/src/utils/animations.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 736 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/NetflixClone/src/utils/animations.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/NetflixClone/src/utils/animations.js
-
curl -L -o animations.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/NetflixClone/src/utils/animations.js
736 Bytes
| export const scrollTo = (element, to, duration, scrollToDone = null) => { | |
| Math.easeInOutQuad = (t, b, c, d) => { | |
| t /= d / 2; | |
| if (t < 1) return c / 2 * t * t + b; | |
| t--; | |
| return -c / 2 * (t * (t - 2) - 1) + b; | |
| }; | |
| let start = element.scrollLeft, | |
| change = to - start, | |
| currentTime = 0, | |
| increment = 20; | |
| const animateScroll = () => { | |
| currentTime += increment; | |
| const val = Math.easeInOutQuad(currentTime, start, change, duration); | |
| element.scrollLeft = val; | |
| if (currentTime < duration) { | |
| setTimeout(animateScroll, increment); | |
| } else { | |
| if (scrollToDone) scrollToDone(); | |
| } | |
| }; | |
| animateScroll(); | |
| } | |