Search
 
SCRIPT & CODE EXAMPLE
 

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' }}
    >
Comment

useScroll

import { useState } from "react";

export const useScroll = () => {

  const [scrollPosition, setScrollPosition] = useState(0);

  const handleScroll = () => {
    const position = window.pageYOffset;
    setScrollPosition(position);
  };
  window.addEventListener("scroll", handleScroll);

  return {scrollPosition};
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to export multiple functions react from one file 
Javascript :: sliding window algorithm javascript 
Javascript :: Navigator operation requested with a context that does not include a Navigator. 
Javascript :: jquery on multiple events 
Javascript :: local vs global variables 
Javascript :: javascript convert input to lowercase 
Javascript :: Alpinejs notification 
Javascript :: angular ionic capacitor nfc reader 
Javascript :: java script remove last charecter from the string 
Javascript :: uncheck multiple checkboxes javascript 
Javascript :: fontawesome icon size 1.5 angular 
Javascript :: hti laravel route from javascript file 
Javascript :: incoroporate js and css file in html 
Javascript :: javascript window.onpopstate example 
Javascript :: v-for only getting one first value vuejs 
Javascript :: outer click on div hide div in jqeury 
Javascript :: Flatten a multidimension array 
Javascript :: convert milliseconds to time javascript 
Javascript :: dynamic button click event in jquery 
Javascript :: js get browser name and platform 
Javascript :: js map key value 
Javascript :: faker.js 
Javascript :: wait for 1 second in loop in javascript 
Javascript :: postgres boolean column 
Javascript :: javascript divide string into two parts 
Javascript :: validar array vacio javascript 
Javascript :: check browser 
Javascript :: serve static files from express 
Javascript :: javascript add element to serialized form array 
Javascript :: function countdown() 21 sec 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =