Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

countup on scroll react only once

import React, { useState } from "react";
import CountUp from "react-countup";
import VisibilitySensor from "react-visibility-sensor";

const Ticker = ({ className, ...rest }) => {
  const [viewPortEntered, setViewPortEntered] = useState(false);

  return (
    <CountUp {...rest} start={viewPortEntered ? null : 0}>
      {({ countUpRef }) => {
        return (
          <VisibilitySensor
            active={!viewPortEntered}
            onChange={isVisible => {
              if (isVisible) {
                setViewPortEntered(true);
              }
            }}
            delayedCall
          >
            <h4 className={className} ref={countUpRef} />
          </VisibilitySensor>
        );
      }}
    </CountUp>
  );
};

export default Ticker;
Comment

React count up on scroll

<CountUp start={0} end={4.8} duration={2} decimals={1}>
    {({ countUpRef, start }) => (
        <VisibilitySensor onChange={start}>
            <span ref={countUpRef} />
        </VisibilitySensor>
    )}
 </CountUp>
Comment

PREVIOUS NEXT
Code Example
Javascript :: jqery get text 
Javascript :: react select with custom option 
Javascript :: moment compare time 
Javascript :: javascript get item in array by id 
Javascript :: js if array is 2d 
Javascript :: javascript trigger event 
Javascript :: js localstorage add text 
Javascript :: javascript hours minutes seconds 
Javascript :: javascript on window resize 
Javascript :: read xlsx file in angular 5 
Javascript :: how to check if all inputs are not empty with javascript 
Javascript :: dot env react native 
Javascript :: how to set env variables in js 
Javascript :: forin js 
Javascript :: promisify 
Javascript :: dynamodb pagination nodejs 
Javascript :: antd datepicker set min max 
Javascript :: string json to class c# 
Javascript :: discord js bot embed user profile picture 
Javascript :: vue js computed 
Javascript :: _id to id 
Javascript :: array filter 
Javascript :: javascript copy 2d array 
Javascript :: loop through array in javascript 
Javascript :: javascript json deserialize 
Javascript :: Easy REACT download image 
Javascript :: merge array of objects javascript 
Javascript :: fabric download 
Javascript :: change image src using jquery 
Javascript :: link href javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =