Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

useHorizontalScroll react

// custom Hook
export const useHorizontalScroll = (scrollWidth: number) => {
  const elRef = useRef();
  useEffect(() => {
    const el = elRef.current as HTMLElement;
    if (el) {
      const onWheel = (e) => {
        console.log(el);

        if (e.deltaY == 0) return;
        e.preventDefault();
        el.scrollTo({
          left: el.scrollLeft + scrollWidth * e.deltaY,
          behavior: 'smooth',
        });
      };
      el.addEventListener('wheel', onWheel);
      return () => el.removeEventListener('wheel', onWheel);
    }
  });
  return elRef;
};

//useage inside a component

const Assessments = () => {
  const scrollRef = useHorizontalScroll(scrollWidth);
  return (
    <div
      ref={scrollRef}
      >
       ......
  )

Comment

PREVIOUS NEXT
Code Example
Typescript :: python Implement the function is_even(number) which gets an integer as input parameter and checks, if this input is even or not 
Typescript :: minikube arguments --cpus 
Typescript :: get alphabets and space only from xml file in android studio 
Typescript :: What are the components of the environment? Explain it along with the examples class 6 
Typescript :: js Validating sets 
Typescript :: jest aliases typescript storybook 
Typescript :: how to get all dates from range in react js 
Typescript :: flutter firestore collection snapshots queries tutorial 
Typescript :: typescript optional parameters 
Typescript :: typescript set interface values to undefined 
Typescript :: first k digits of n*n 
Typescript :: c code for insrting elements in set 
Typescript :: js Validating nested promises 
Typescript :: nullish coalescing angular example 
Typescript :: use array element as types 
Typescript :: install beats on rasberry 
Typescript :: writhing requests to text file 
Typescript :: length functioni in typesrcipt 
Typescript :: generic function typescript 
Typescript :: filtering objects in django templates 
Typescript :: t sql if exists multiple conditions 
Typescript :: Coding Exercise: Double Time Modify this recursive program to correctly count down in increments of 2. 
Cpp :: c++ starter 
Cpp :: flutter margins 
Cpp :: c++ directory listing 
Cpp :: c++ usleep() 
Cpp :: how to find index of a vector in c++ 
Cpp :: c++ pause 
Cpp :: what is difference between single inverted and double inverted in programming languages 
Cpp :: C++ Fahrenheit to Celsius 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =