Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mouse wheel scroll sections in react

import React, { Component } from "react";
import ReactScrollWheelHandler from " react-scroll-wheel-handler";

class App extends React.Component {
  state = {
    currentIndex: 0,
    colors: ["red", "black", "grey", "blue", "green"],
  };
  nextIndex = () => {
    const { colors, currentIndex } = this.state;
    if (currentIndex == colors.length - 1) {
      return this.setState({ currentIndex: 0 });
    }

    return this.setState({
      currentIndex: currentIndex + 1,
    });
  };

  prevIndex = () => {
    const { colors, currentIndex } = this.state;
    if (currentIndex == 0) {
      return this.setState({
        currentIndex: colors.length - 1,
      });
    }

    return this.setState({
      currentIndex: currentIndex - 1,
    });
  };

  render() {
    const { colors, currentIndex } = this.state;
    return (
      <div>
        <ReactScrollWheelHandler
          upHandler={this.prevIndex}
          downHandler={this.nextIndex}
          style={{
            width: "100%",
            height: "100vh",
            backgroundColor: colors[currentIndex],
            transition: "background-color .4s ease-out",
          }}
        >
          <h1>SCROLL FOR CHANGE BACKGROUND COLOR</h1>
        </ReactScrollWheelHandler>
      </div>
    );
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: uppercase each word javascript 
Javascript :: react js how to do array range 
Javascript :: remove last word from string javascript 
Javascript :: Get home directory in nodejs windows 
Javascript :: function syntax js 
Javascript :: set twig variable from javascript 
Javascript :: update password before saving to mongodb 
Javascript :: javascript array loop back 
Javascript :: change h2 to h1 using javascript 
Javascript :: mongoose objectid parse 
Javascript :: how to create a search engine with javascript 
Javascript :: url 
Javascript :: javascript json error html 
Javascript :: convert arrow function to normal function javascript online 
Python :: python int64index 
Python :: django EMAIL_BACKEND console 
Python :: drop last row pandas 
Python :: remove all pyc files 
Python :: python currnent time 
Python :: CMake Error at 3rdparty/GLFW/CMakeLists.txt:236 (message): The RandR headers were not found 
Python :: python spawn shell 
Python :: python clear console 
Python :: remove python ubuntu 
Python :: get stats from array python 
Python :: seaborn size 
Python :: current datetime pandas 
Python :: django no such table 
Python :: Getting Random rows in dataframe 
Python :: loop through list backwards python 
Python :: plot to image python 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =