Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

useScroll hooks

import { useInView } from 'react-intersection-observer';
import { useAnimation } from 'framer-motion';

export const useScroll = (thresh = 0.3) => {
  const controls = useAnimation();
  const { ref, inView } = useInView({ threshold: thresh });

  if (inView) {
    controls.start('show');
  } else {
    controls.start('hidden');
  }

  return { ref, controls };
};


//Video.tsx
import { useScroll } from '../../hooks/useScroll';
import { fade, titleAnim } from '../../../utils/animation';
const Video = () => {
  const { width } = useWindowSize();
  const videoRef = useRef<any>();
   const { ref, controls } = useScroll();
  return (
    <VideoSection
      transition={{ duration: 0.75 }}
      ref={ref}
      variants={reveal}
      animate={controls}
      initial="hidden"
      className="section-wrapper"
      width={width}
      style={{ marginTop: '-20px' }}
    >
 
PREVIOUS NEXT
Tagged: #useScroll #hooks
ADD COMMENT
Topic
Name
7+5 =