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 :: random index js 
Javascript :: show 5 entries in datatable 
Javascript :: border react native 
Javascript :: react native transparent color 
Javascript :: angular moment 
Javascript :: update node-modules 
Javascript :: jquery onclick function 
Javascript :: js regex email 
Javascript :: for loop in ejs 
Javascript :: javascript detect mobile browser 
Javascript :: graphqlHTTP is not a function 
Javascript :: javascript how to get a random element from an array 
Javascript :: discord bot status javascript 
Javascript :: jquery ajax post form 
Javascript :: Manifest 3 content security policy 
Javascript :: javascript change string at particular index 
Javascript :: get local storage javascript 
Javascript :: increase font size chartjs 
Javascript :: remove all dots from string javascript 
Javascript :: angular create project in current directory 
Javascript :: delegate jquery 
Javascript :: javascript add required attribute to input 
Javascript :: mouse coordinates not match with canvas coordinate 
Javascript :: jquery avoid enter submit 
Javascript :: add quotes to array values javascript 
Javascript :: onchange select dropdown jquery 
Javascript :: js convert nodelist to array 
Javascript :: javascript factorial 
Javascript :: react native open email client 
Javascript :: javascript convert number to hex 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =