anecko
Content Type
Profiles
Forums
Store
Blog
Product
Showcase
FAQ
Downloads
Posts posted by anecko
-
-
import { gsap } from 'gsap';import ScrollTrigger from 'gsap/dist/ScrollTrigger';if (typeof window !== 'undefined') {gsap.registerPlugin(ScrollTrigger);}function getCurrentFrame(index) {return `assets/frames/process_0${index.toString().padStart(4, '0')}.jpg`;}export const CanvasScroll = ({ scrollHeight, numFrames, width, height, svgRef }) => {const canvasRef = React.useRef(null);const [images, setImages] = React.useState([]);const [frameIndex, setFrameIndex] = React.useState(0);function preloadImages() {for (let i = 1; i <= numFrames; i++) {const img = new Image(100, 100);const imgSrc = getCurrentFrame(i);img.src = imgSrc;setImages((prevImages) => [...prevImages, img]);}}const handleScroll = () => {const scrollFraction = window.scrollY / (scrollHeight - window.innerHeight);const index = Math.min(numFrames - 1, Math.ceil(scrollFraction * numFrames));if (index <= 0 || index > numFrames) {return;}setFrameIndex(index);};const renderCanvas = () => {const context = canvasRef.current.getContext('2d');context.canvas.width = width;context.canvas.height = height;};React.useEffect(() => {preloadImages();renderCanvas();window.addEventListener('scroll', handleScroll);return () => window.removeEventListener('scroll', handleScroll);}, []);React.useEffect(() => {if (!canvasRef.current || images.length < 1) {return;}const context = canvasRef.current.getContext('2d');let requestId;const render = () => {context.drawImage(images[frameIndex], 0, 0);requestId = requestAnimationFrame(render);};render();return () => cancelAnimationFrame(requestId);}, [frameIndex, images]);React.useEffect(() => {const t = gsap.to('.canvas', {scrollTrigger: {trigger: svgRef.current,start: 'top top',end: '+=' + numFrames * scrollHeight,},});return () => {t.kill();ScrollTrigger.getAll().forEach((e) => e.kill());};}, []);return (<div className="canvas"><canvas ref={canvasRef} /></div>);};
-
How to rewrite it on React?
See the Pen 2152a28cffe2c2c0cca8a3e47f7b21c6 by osublake (@osublake) on CodePen
-
-
@Rodrigo The example does not work (
-
here is a piece of code, it doesn't work for some reason, but it should change the collar of the circle when scrolling down
https://codesandbox.io/s/codepen-with-react-forked-irio8r?file=/src/components/App.js
-
@kodralex so what's on your website
-
-
-
@Cassie look at how this code works -
See the Pen bGmRoBo by GreenSock (@GreenSock) on CodePen
and this - https://stackblitz.com/edit/react-4q639w?file=src%2FApp.js, I need them to work like on simple js but to transfer evo to react -
@GreenSock I want to do this but something is not working for me, and you also have bugs with it there
See the Pen bGmRoBo by GreenSock (@GreenSock) on CodePen
-
-
@GreenSock did as here, for some reason it breaks all the time - https://stackblitz.com/edit/react-cxv92j?file=src%2FApp.js
-
@GreenSock it breaks on my react project, how can it be fixed in this case?
-
Thank you very much
-
-
how to change this code to the one in the video?
https://gyazo.com/847d30e010cca560fce5f60067ce9047
See the Pen MWmVwpX by GreenSock (@GreenSock) on CodePen
How to rewrite it on React?
in GSAP
Posted
https://stackblitz.com/edit/react-o4zdyx?file=src%2FApp.js