Replicating transition based on intersection observerSimplest code for array intersection in javascriptIntersection observer does not work with target with position: fixedSingle animation on stateless React componentHow to debounce or throttle Intersection Observer?Intersection Observer not running in FFLazy load with Intersection Observer and offsetIntersection Observer when element leaves the viewportIntersection Observers with DOM siblingsIntersection observer thresholds value not workingCallback for intersection observer being called for images that are not intersecting

Is this car delivery via Ebay Motors on Craigslist a scam?

Why did the frequency of the word "черт" (devil) in books increase by a few times since the October Revolution?

Uniform initialization by tuple

Was it ever illegal to name a pig "Napoleon" in France?

How to reclaim personal item I've lent to the office without burning bridges?

3-way switches no longer serving their purpose

Can a wizard use the spell Levitate on a target and shoot him with attacking spells that don't require concentration?

Possibility to correct pitch from digital versions of records with the hole not centered

Is it ok for parents to kiss and romance with each other while their 2- to 8-year-old child watches?

Interpretation of non-significant results as "trends"

Did William Shakespeare hide things in his writings?

Taking my Ph.D. advisor out for dinner after graduation

I'm feeling like my character doesn't fit the campaign

Those who speak do not know, those who know do not speak

Why did Robert F. Kennedy loathe Lyndon B. Johnson?

Why do Martians have to wear space helmets?

Is conquering your neighbors to fight a greater enemy a valid strategy?

How to understand flavors and when to use combination of them?

I don't want to be introduced as a "Minority Novelist"

Sorting a list according to some pre-specified rules

What is the meaning of "prairie-dog" in this sentence?

What does "spinning upon the shoals" mean?

Why do airports remove/realign runways?

How should I ask for a "pint" in countries that use metric?



Replicating transition based on intersection observer


Simplest code for array intersection in javascriptIntersection observer does not work with target with position: fixedSingle animation on stateless React componentHow to debounce or throttle Intersection Observer?Intersection Observer not running in FFLazy load with Intersection Observer and offsetIntersection Observer when element leaves the viewportIntersection Observers with DOM siblingsIntersection observer thresholds value not workingCallback for intersection observer being called for images that are not intersecting






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have been working on the side project, where I was requested to build a website with some animations around it. I choose to start with React (to learn a new framework and expand my knowledge).



The one important animation which I am following (or trying to replicate) is from Apple website.



When you start the webpage and scroll down the text appears smoothly by moving 60px and changing the opacity. Once it is in the view port.



I tried to do this with classes. However, I would get issues with classes as they would sometimes re-render my element or the component would not be visible when I refresh.



I also tried to use some fadeIn with setInterval, however, this works differently every time it is activated.



My component which uses the animations:




import React, Component from "react";
import "./SuccessStory.css";

class SuccessStory extends Component
state =
componentAppearsScrollUp: false,
componentDisappearsScrollUp: false,
componentAppearsScrollDown: false,
componentDisappearsScrollDown: false,
showComponent: false,
translateMove: 60,
opacity: 0
;

fadingIn()
const timer = setInterval(() =>
if (this.state.opacity >= 1)
clearInterval(timer);
return;

this.setState(
opacity: this.state.opacity + 0.05
);
, 100);


fadingOut()
const timer = setInterval(() =>
if (this.state.opacity <= 0)
clearInterval(timer);

this.setState(
opacity: this.state.opacity - 0.05
);
, 100);


componentDidUpdate(prevProps, prevState)
if (this.props.currentY < prevProps.currentY)
if (
this.props.intersectionRatio > prevProps.intersectionRatio &&
this.props.isIntersecting
)
if (this.props.intersectionRatio > 0.6)
console.log("Scrolling down enter");
this.fadingIn();
this.setState(
componentAppearsScrollUp: false,
componentDisappearsScrollUp: false,
componentAppearsScrollDown: true,
componentDisappearsScrollDown: false,
showComponent: true
);

else
if (
this.props.intersectionRatio < 0.8 &&
this.props.intersectionRatio > 0.6
)
console.log("Scrolling down leave");
this.setState(
componentAppearsScrollUp: false,
componentDisappearsScrollUp: false,
componentAppearsScrollDown: false,
componentDisappearsScrollDown: true,
showComponent: true
);
this.fadingOut();


else if (
this.props.currentY > prevProps.currentY &&
this.props.isIntersecting
)
if (this.props.intersectionRatio < prevProps.intersectionRatio)
if (this.props.intersectionRatio < 0.9)
console.log("Scrolling up leave");
this.fadingOut();
this.setState(
componentAppearsScrollUp: false,
componentDisappearsScrollUp: true,
componentAppearsScrollDown: false,
componentDisappearsScrollDown: false,
showComponent: true
);

else
if (
this.props.intersectionRatio > 0.6 &&
this.props.intersectionRatio < 0.8
)
console.log("Scrolling up enter");
this.setState(
componentAppearsScrollUp: true,
componentDisappearsScrollUp: false,
componentAppearsScrollDown: false,
componentDisappearsScrollDown: false,
showComponent: true
);
this.fadingIn();


else if (
this.props.isIntersecting &&
this.props.intersectionRatio > 0.9
)
this.fadingIn();



render()
return (
<div
className=
(this.state.componentAppearsScrollDown
? " story-appear-scroll-down "
: "") +
(this.state.componentDisappearsScrollDown
? " story-disappear-scroll-down "
: "") +
(this.state.componentAppearsScrollUp
? "story-appear-scroll-up "
: "") +
(this.state.componentDisappearsScrollUp
? " story-disappear-scroll-up "
: "")

style=
opacity: this.state.opacity

>
<h1 className="success-story">The success story</h1>
<h2
className="success-story-text-one"
// style=
// this.props.isIntersecting && this.props.intersectionRatio > 0.8
// ? opacity: 1
// : opacity: 0
//
>
MobileLife brought together over 100 dedicated people based in
Copenhagen and Vilnius to deliver innovative mobile solutions to the
banking customers in Nordic markets.
</h2>
</div>
);



export default SuccessStory;


My parent component which passes the intersection observer values to the child component:




import React, Component from "react";
import "./SecondPage.css";
import SuccessStory from "./SuccessStory";
import InView from "react-intersection-observer";
// import SuccessStoryText1 from "./SuccessStoryText1";
import SuccessStoryText2 from "./SuccessStoryText2";

class SecondPage extends Component
state =
isIntersecting: false,
intersectionRatio: "",
currentY: "",
isIntersectingSecondText: false,
intersectionRatioSecondText: "",
currentYSecondText: ""
;

render()
return (
<div className="second-page">
<div className="navigation-second" style= position: "sticky" />
<div style= paddingTop: "25%", height: "60vh" >
<InView
threshold=[0.1, 0.2, 0.3, 0.4, 0.6, 0.75, 0.8]
onChange=(inView, ref) =>
this.setState(
currentY: ref.boundingClientRect.y,
isIntersecting: ref.isIntersecting,
intersectionRatio: ref.intersectionRatio
);

// console.log("Inview:", inView, ref);

>
( inView, ref ) => (
<div ref=ref style= position: "sticky", top: "30%" >
<SuccessStory
isIntersecting=this.state.isIntersecting
intersectionRatio=this.state.intersectionRatio
currentY=this.state.currentY
/>
</div>
)
</InView>
</div>

<InView
threshold=[0.1, 0.2, 0.3, 0.4, 0.6, 0.75, 0.8]
onChange=(inView, ref) =>
if (ref.intersectionRatio > 0.1)
this.setState(
currentYSecondText: ref.boundingClientRect.y,
isIntersectingSecondText: ref.isIntersecting,
intersectionRatioSecondText: ref.intersectionRatio
);

// console.log("Inview:", inView, ref);

>
( inView, ref ) => (
<div ref=ref>
<SuccessStoryText2
isIntersecting=this.state.isIntersectingSecondText
intersectionRatio=this.state.intersectionRatioSecondText
currentY=this.state.currentYSecondText
/>
</div>
)
</InView>
</div>
);


//
export default SecondPage;




And here is Css which I am using for the animations:



.story-appear-scroll-down 
animation: successStoryTextAppearScrollDown 0.3s linear;
animation-fill-mode: forwards;


@keyframes successStoryTextAppearScrollDown
from
transform: translate3d(0, 60px, 0);

to
transform: translate3d(0, 0, 0);



.story-disappear-scroll-down
animation: successStoryTextDisappearScrollDown 0.3s linear;
animation-fill-mode: forwards;


@keyframes successStoryTextDisappearScrollDown
from
transform: translate3d(0, 0, 0);

to
transform: translate3d(0, 0, 0);



.story-appear-scroll-up
animation: successStoryTextAppearScrollUp 0.3s linear;
animation-fill-mode: forwards;


@keyframes successStoryTextAppearScrollUp
from
transform: translate3d(0, 0, 0);

to
transform: translate3d(0, 0, 0);



.story-disappear-scroll-up
animation: successStoryTextDisappearScrollUp 0.3s linear;
animation-fill-mode: forwards;


@keyframes successStoryTextDisappearScrollUp
from
transform: translate3d(0, 0, 0);

to
transform: translate3d(0, 60px, 0);




I was thinking what would be correct way to activate this kind of animation which I am trying to replicate and it would look the same every time it is activated (as in Apple webpage). As I already have spent too much time on this, however, I am not able to get the results that I want.



I appreciate your help, and any tips or suggestions are welcome as this is my first post.










share|improve this question






























    1















    I have been working on the side project, where I was requested to build a website with some animations around it. I choose to start with React (to learn a new framework and expand my knowledge).



    The one important animation which I am following (or trying to replicate) is from Apple website.



    When you start the webpage and scroll down the text appears smoothly by moving 60px and changing the opacity. Once it is in the view port.



    I tried to do this with classes. However, I would get issues with classes as they would sometimes re-render my element or the component would not be visible when I refresh.



    I also tried to use some fadeIn with setInterval, however, this works differently every time it is activated.



    My component which uses the animations:




    import React, Component from "react";
    import "./SuccessStory.css";

    class SuccessStory extends Component
    state =
    componentAppearsScrollUp: false,
    componentDisappearsScrollUp: false,
    componentAppearsScrollDown: false,
    componentDisappearsScrollDown: false,
    showComponent: false,
    translateMove: 60,
    opacity: 0
    ;

    fadingIn()
    const timer = setInterval(() =>
    if (this.state.opacity >= 1)
    clearInterval(timer);
    return;

    this.setState(
    opacity: this.state.opacity + 0.05
    );
    , 100);


    fadingOut()
    const timer = setInterval(() =>
    if (this.state.opacity <= 0)
    clearInterval(timer);

    this.setState(
    opacity: this.state.opacity - 0.05
    );
    , 100);


    componentDidUpdate(prevProps, prevState)
    if (this.props.currentY < prevProps.currentY)
    if (
    this.props.intersectionRatio > prevProps.intersectionRatio &&
    this.props.isIntersecting
    )
    if (this.props.intersectionRatio > 0.6)
    console.log("Scrolling down enter");
    this.fadingIn();
    this.setState(
    componentAppearsScrollUp: false,
    componentDisappearsScrollUp: false,
    componentAppearsScrollDown: true,
    componentDisappearsScrollDown: false,
    showComponent: true
    );

    else
    if (
    this.props.intersectionRatio < 0.8 &&
    this.props.intersectionRatio > 0.6
    )
    console.log("Scrolling down leave");
    this.setState(
    componentAppearsScrollUp: false,
    componentDisappearsScrollUp: false,
    componentAppearsScrollDown: false,
    componentDisappearsScrollDown: true,
    showComponent: true
    );
    this.fadingOut();


    else if (
    this.props.currentY > prevProps.currentY &&
    this.props.isIntersecting
    )
    if (this.props.intersectionRatio < prevProps.intersectionRatio)
    if (this.props.intersectionRatio < 0.9)
    console.log("Scrolling up leave");
    this.fadingOut();
    this.setState(
    componentAppearsScrollUp: false,
    componentDisappearsScrollUp: true,
    componentAppearsScrollDown: false,
    componentDisappearsScrollDown: false,
    showComponent: true
    );

    else
    if (
    this.props.intersectionRatio > 0.6 &&
    this.props.intersectionRatio < 0.8
    )
    console.log("Scrolling up enter");
    this.setState(
    componentAppearsScrollUp: true,
    componentDisappearsScrollUp: false,
    componentAppearsScrollDown: false,
    componentDisappearsScrollDown: false,
    showComponent: true
    );
    this.fadingIn();


    else if (
    this.props.isIntersecting &&
    this.props.intersectionRatio > 0.9
    )
    this.fadingIn();



    render()
    return (
    <div
    className=
    (this.state.componentAppearsScrollDown
    ? " story-appear-scroll-down "
    : "") +
    (this.state.componentDisappearsScrollDown
    ? " story-disappear-scroll-down "
    : "") +
    (this.state.componentAppearsScrollUp
    ? "story-appear-scroll-up "
    : "") +
    (this.state.componentDisappearsScrollUp
    ? " story-disappear-scroll-up "
    : "")

    style=
    opacity: this.state.opacity

    >
    <h1 className="success-story">The success story</h1>
    <h2
    className="success-story-text-one"
    // style=
    // this.props.isIntersecting && this.props.intersectionRatio > 0.8
    // ? opacity: 1
    // : opacity: 0
    //
    >
    MobileLife brought together over 100 dedicated people based in
    Copenhagen and Vilnius to deliver innovative mobile solutions to the
    banking customers in Nordic markets.
    </h2>
    </div>
    );



    export default SuccessStory;


    My parent component which passes the intersection observer values to the child component:




    import React, Component from "react";
    import "./SecondPage.css";
    import SuccessStory from "./SuccessStory";
    import InView from "react-intersection-observer";
    // import SuccessStoryText1 from "./SuccessStoryText1";
    import SuccessStoryText2 from "./SuccessStoryText2";

    class SecondPage extends Component
    state =
    isIntersecting: false,
    intersectionRatio: "",
    currentY: "",
    isIntersectingSecondText: false,
    intersectionRatioSecondText: "",
    currentYSecondText: ""
    ;

    render()
    return (
    <div className="second-page">
    <div className="navigation-second" style= position: "sticky" />
    <div style= paddingTop: "25%", height: "60vh" >
    <InView
    threshold=[0.1, 0.2, 0.3, 0.4, 0.6, 0.75, 0.8]
    onChange=(inView, ref) =>
    this.setState(
    currentY: ref.boundingClientRect.y,
    isIntersecting: ref.isIntersecting,
    intersectionRatio: ref.intersectionRatio
    );

    // console.log("Inview:", inView, ref);

    >
    ( inView, ref ) => (
    <div ref=ref style= position: "sticky", top: "30%" >
    <SuccessStory
    isIntersecting=this.state.isIntersecting
    intersectionRatio=this.state.intersectionRatio
    currentY=this.state.currentY
    />
    </div>
    )
    </InView>
    </div>

    <InView
    threshold=[0.1, 0.2, 0.3, 0.4, 0.6, 0.75, 0.8]
    onChange=(inView, ref) =>
    if (ref.intersectionRatio > 0.1)
    this.setState(
    currentYSecondText: ref.boundingClientRect.y,
    isIntersectingSecondText: ref.isIntersecting,
    intersectionRatioSecondText: ref.intersectionRatio
    );

    // console.log("Inview:", inView, ref);

    >
    ( inView, ref ) => (
    <div ref=ref>
    <SuccessStoryText2
    isIntersecting=this.state.isIntersectingSecondText
    intersectionRatio=this.state.intersectionRatioSecondText
    currentY=this.state.currentYSecondText
    />
    </div>
    )
    </InView>
    </div>
    );


    //
    export default SecondPage;




    And here is Css which I am using for the animations:



    .story-appear-scroll-down 
    animation: successStoryTextAppearScrollDown 0.3s linear;
    animation-fill-mode: forwards;


    @keyframes successStoryTextAppearScrollDown
    from
    transform: translate3d(0, 60px, 0);

    to
    transform: translate3d(0, 0, 0);



    .story-disappear-scroll-down
    animation: successStoryTextDisappearScrollDown 0.3s linear;
    animation-fill-mode: forwards;


    @keyframes successStoryTextDisappearScrollDown
    from
    transform: translate3d(0, 0, 0);

    to
    transform: translate3d(0, 0, 0);



    .story-appear-scroll-up
    animation: successStoryTextAppearScrollUp 0.3s linear;
    animation-fill-mode: forwards;


    @keyframes successStoryTextAppearScrollUp
    from
    transform: translate3d(0, 0, 0);

    to
    transform: translate3d(0, 0, 0);



    .story-disappear-scroll-up
    animation: successStoryTextDisappearScrollUp 0.3s linear;
    animation-fill-mode: forwards;


    @keyframes successStoryTextDisappearScrollUp
    from
    transform: translate3d(0, 0, 0);

    to
    transform: translate3d(0, 60px, 0);




    I was thinking what would be correct way to activate this kind of animation which I am trying to replicate and it would look the same every time it is activated (as in Apple webpage). As I already have spent too much time on this, however, I am not able to get the results that I want.



    I appreciate your help, and any tips or suggestions are welcome as this is my first post.










    share|improve this question


























      1












      1








      1








      I have been working on the side project, where I was requested to build a website with some animations around it. I choose to start with React (to learn a new framework and expand my knowledge).



      The one important animation which I am following (or trying to replicate) is from Apple website.



      When you start the webpage and scroll down the text appears smoothly by moving 60px and changing the opacity. Once it is in the view port.



      I tried to do this with classes. However, I would get issues with classes as they would sometimes re-render my element or the component would not be visible when I refresh.



      I also tried to use some fadeIn with setInterval, however, this works differently every time it is activated.



      My component which uses the animations:




      import React, Component from "react";
      import "./SuccessStory.css";

      class SuccessStory extends Component
      state =
      componentAppearsScrollUp: false,
      componentDisappearsScrollUp: false,
      componentAppearsScrollDown: false,
      componentDisappearsScrollDown: false,
      showComponent: false,
      translateMove: 60,
      opacity: 0
      ;

      fadingIn()
      const timer = setInterval(() =>
      if (this.state.opacity >= 1)
      clearInterval(timer);
      return;

      this.setState(
      opacity: this.state.opacity + 0.05
      );
      , 100);


      fadingOut()
      const timer = setInterval(() =>
      if (this.state.opacity <= 0)
      clearInterval(timer);

      this.setState(
      opacity: this.state.opacity - 0.05
      );
      , 100);


      componentDidUpdate(prevProps, prevState)
      if (this.props.currentY < prevProps.currentY)
      if (
      this.props.intersectionRatio > prevProps.intersectionRatio &&
      this.props.isIntersecting
      )
      if (this.props.intersectionRatio > 0.6)
      console.log("Scrolling down enter");
      this.fadingIn();
      this.setState(
      componentAppearsScrollUp: false,
      componentDisappearsScrollUp: false,
      componentAppearsScrollDown: true,
      componentDisappearsScrollDown: false,
      showComponent: true
      );

      else
      if (
      this.props.intersectionRatio < 0.8 &&
      this.props.intersectionRatio > 0.6
      )
      console.log("Scrolling down leave");
      this.setState(
      componentAppearsScrollUp: false,
      componentDisappearsScrollUp: false,
      componentAppearsScrollDown: false,
      componentDisappearsScrollDown: true,
      showComponent: true
      );
      this.fadingOut();


      else if (
      this.props.currentY > prevProps.currentY &&
      this.props.isIntersecting
      )
      if (this.props.intersectionRatio < prevProps.intersectionRatio)
      if (this.props.intersectionRatio < 0.9)
      console.log("Scrolling up leave");
      this.fadingOut();
      this.setState(
      componentAppearsScrollUp: false,
      componentDisappearsScrollUp: true,
      componentAppearsScrollDown: false,
      componentDisappearsScrollDown: false,
      showComponent: true
      );

      else
      if (
      this.props.intersectionRatio > 0.6 &&
      this.props.intersectionRatio < 0.8
      )
      console.log("Scrolling up enter");
      this.setState(
      componentAppearsScrollUp: true,
      componentDisappearsScrollUp: false,
      componentAppearsScrollDown: false,
      componentDisappearsScrollDown: false,
      showComponent: true
      );
      this.fadingIn();


      else if (
      this.props.isIntersecting &&
      this.props.intersectionRatio > 0.9
      )
      this.fadingIn();



      render()
      return (
      <div
      className=
      (this.state.componentAppearsScrollDown
      ? " story-appear-scroll-down "
      : "") +
      (this.state.componentDisappearsScrollDown
      ? " story-disappear-scroll-down "
      : "") +
      (this.state.componentAppearsScrollUp
      ? "story-appear-scroll-up "
      : "") +
      (this.state.componentDisappearsScrollUp
      ? " story-disappear-scroll-up "
      : "")

      style=
      opacity: this.state.opacity

      >
      <h1 className="success-story">The success story</h1>
      <h2
      className="success-story-text-one"
      // style=
      // this.props.isIntersecting && this.props.intersectionRatio > 0.8
      // ? opacity: 1
      // : opacity: 0
      //
      >
      MobileLife brought together over 100 dedicated people based in
      Copenhagen and Vilnius to deliver innovative mobile solutions to the
      banking customers in Nordic markets.
      </h2>
      </div>
      );



      export default SuccessStory;


      My parent component which passes the intersection observer values to the child component:




      import React, Component from "react";
      import "./SecondPage.css";
      import SuccessStory from "./SuccessStory";
      import InView from "react-intersection-observer";
      // import SuccessStoryText1 from "./SuccessStoryText1";
      import SuccessStoryText2 from "./SuccessStoryText2";

      class SecondPage extends Component
      state =
      isIntersecting: false,
      intersectionRatio: "",
      currentY: "",
      isIntersectingSecondText: false,
      intersectionRatioSecondText: "",
      currentYSecondText: ""
      ;

      render()
      return (
      <div className="second-page">
      <div className="navigation-second" style= position: "sticky" />
      <div style= paddingTop: "25%", height: "60vh" >
      <InView
      threshold=[0.1, 0.2, 0.3, 0.4, 0.6, 0.75, 0.8]
      onChange=(inView, ref) =>
      this.setState(
      currentY: ref.boundingClientRect.y,
      isIntersecting: ref.isIntersecting,
      intersectionRatio: ref.intersectionRatio
      );

      // console.log("Inview:", inView, ref);

      >
      ( inView, ref ) => (
      <div ref=ref style= position: "sticky", top: "30%" >
      <SuccessStory
      isIntersecting=this.state.isIntersecting
      intersectionRatio=this.state.intersectionRatio
      currentY=this.state.currentY
      />
      </div>
      )
      </InView>
      </div>

      <InView
      threshold=[0.1, 0.2, 0.3, 0.4, 0.6, 0.75, 0.8]
      onChange=(inView, ref) =>
      if (ref.intersectionRatio > 0.1)
      this.setState(
      currentYSecondText: ref.boundingClientRect.y,
      isIntersectingSecondText: ref.isIntersecting,
      intersectionRatioSecondText: ref.intersectionRatio
      );

      // console.log("Inview:", inView, ref);

      >
      ( inView, ref ) => (
      <div ref=ref>
      <SuccessStoryText2
      isIntersecting=this.state.isIntersectingSecondText
      intersectionRatio=this.state.intersectionRatioSecondText
      currentY=this.state.currentYSecondText
      />
      </div>
      )
      </InView>
      </div>
      );


      //
      export default SecondPage;




      And here is Css which I am using for the animations:



      .story-appear-scroll-down 
      animation: successStoryTextAppearScrollDown 0.3s linear;
      animation-fill-mode: forwards;


      @keyframes successStoryTextAppearScrollDown
      from
      transform: translate3d(0, 60px, 0);

      to
      transform: translate3d(0, 0, 0);



      .story-disappear-scroll-down
      animation: successStoryTextDisappearScrollDown 0.3s linear;
      animation-fill-mode: forwards;


      @keyframes successStoryTextDisappearScrollDown
      from
      transform: translate3d(0, 0, 0);

      to
      transform: translate3d(0, 0, 0);



      .story-appear-scroll-up
      animation: successStoryTextAppearScrollUp 0.3s linear;
      animation-fill-mode: forwards;


      @keyframes successStoryTextAppearScrollUp
      from
      transform: translate3d(0, 0, 0);

      to
      transform: translate3d(0, 0, 0);



      .story-disappear-scroll-up
      animation: successStoryTextDisappearScrollUp 0.3s linear;
      animation-fill-mode: forwards;


      @keyframes successStoryTextDisappearScrollUp
      from
      transform: translate3d(0, 0, 0);

      to
      transform: translate3d(0, 60px, 0);




      I was thinking what would be correct way to activate this kind of animation which I am trying to replicate and it would look the same every time it is activated (as in Apple webpage). As I already have spent too much time on this, however, I am not able to get the results that I want.



      I appreciate your help, and any tips or suggestions are welcome as this is my first post.










      share|improve this question
















      I have been working on the side project, where I was requested to build a website with some animations around it. I choose to start with React (to learn a new framework and expand my knowledge).



      The one important animation which I am following (or trying to replicate) is from Apple website.



      When you start the webpage and scroll down the text appears smoothly by moving 60px and changing the opacity. Once it is in the view port.



      I tried to do this with classes. However, I would get issues with classes as they would sometimes re-render my element or the component would not be visible when I refresh.



      I also tried to use some fadeIn with setInterval, however, this works differently every time it is activated.



      My component which uses the animations:




      import React, Component from "react";
      import "./SuccessStory.css";

      class SuccessStory extends Component
      state =
      componentAppearsScrollUp: false,
      componentDisappearsScrollUp: false,
      componentAppearsScrollDown: false,
      componentDisappearsScrollDown: false,
      showComponent: false,
      translateMove: 60,
      opacity: 0
      ;

      fadingIn()
      const timer = setInterval(() =>
      if (this.state.opacity >= 1)
      clearInterval(timer);
      return;

      this.setState(
      opacity: this.state.opacity + 0.05
      );
      , 100);


      fadingOut()
      const timer = setInterval(() =>
      if (this.state.opacity <= 0)
      clearInterval(timer);

      this.setState(
      opacity: this.state.opacity - 0.05
      );
      , 100);


      componentDidUpdate(prevProps, prevState)
      if (this.props.currentY < prevProps.currentY)
      if (
      this.props.intersectionRatio > prevProps.intersectionRatio &&
      this.props.isIntersecting
      )
      if (this.props.intersectionRatio > 0.6)
      console.log("Scrolling down enter");
      this.fadingIn();
      this.setState(
      componentAppearsScrollUp: false,
      componentDisappearsScrollUp: false,
      componentAppearsScrollDown: true,
      componentDisappearsScrollDown: false,
      showComponent: true
      );

      else
      if (
      this.props.intersectionRatio < 0.8 &&
      this.props.intersectionRatio > 0.6
      )
      console.log("Scrolling down leave");
      this.setState(
      componentAppearsScrollUp: false,
      componentDisappearsScrollUp: false,
      componentAppearsScrollDown: false,
      componentDisappearsScrollDown: true,
      showComponent: true
      );
      this.fadingOut();


      else if (
      this.props.currentY > prevProps.currentY &&
      this.props.isIntersecting
      )
      if (this.props.intersectionRatio < prevProps.intersectionRatio)
      if (this.props.intersectionRatio < 0.9)
      console.log("Scrolling up leave");
      this.fadingOut();
      this.setState(
      componentAppearsScrollUp: false,
      componentDisappearsScrollUp: true,
      componentAppearsScrollDown: false,
      componentDisappearsScrollDown: false,
      showComponent: true
      );

      else
      if (
      this.props.intersectionRatio > 0.6 &&
      this.props.intersectionRatio < 0.8
      )
      console.log("Scrolling up enter");
      this.setState(
      componentAppearsScrollUp: true,
      componentDisappearsScrollUp: false,
      componentAppearsScrollDown: false,
      componentDisappearsScrollDown: false,
      showComponent: true
      );
      this.fadingIn();


      else if (
      this.props.isIntersecting &&
      this.props.intersectionRatio > 0.9
      )
      this.fadingIn();



      render()
      return (
      <div
      className=
      (this.state.componentAppearsScrollDown
      ? " story-appear-scroll-down "
      : "") +
      (this.state.componentDisappearsScrollDown
      ? " story-disappear-scroll-down "
      : "") +
      (this.state.componentAppearsScrollUp
      ? "story-appear-scroll-up "
      : "") +
      (this.state.componentDisappearsScrollUp
      ? " story-disappear-scroll-up "
      : "")

      style=
      opacity: this.state.opacity

      >
      <h1 className="success-story">The success story</h1>
      <h2
      className="success-story-text-one"
      // style=
      // this.props.isIntersecting && this.props.intersectionRatio > 0.8
      // ? opacity: 1
      // : opacity: 0
      //
      >
      MobileLife brought together over 100 dedicated people based in
      Copenhagen and Vilnius to deliver innovative mobile solutions to the
      banking customers in Nordic markets.
      </h2>
      </div>
      );



      export default SuccessStory;


      My parent component which passes the intersection observer values to the child component:




      import React, Component from "react";
      import "./SecondPage.css";
      import SuccessStory from "./SuccessStory";
      import InView from "react-intersection-observer";
      // import SuccessStoryText1 from "./SuccessStoryText1";
      import SuccessStoryText2 from "./SuccessStoryText2";

      class SecondPage extends Component
      state =
      isIntersecting: false,
      intersectionRatio: "",
      currentY: "",
      isIntersectingSecondText: false,
      intersectionRatioSecondText: "",
      currentYSecondText: ""
      ;

      render()
      return (
      <div className="second-page">
      <div className="navigation-second" style= position: "sticky" />
      <div style= paddingTop: "25%", height: "60vh" >
      <InView
      threshold=[0.1, 0.2, 0.3, 0.4, 0.6, 0.75, 0.8]
      onChange=(inView, ref) =>
      this.setState(
      currentY: ref.boundingClientRect.y,
      isIntersecting: ref.isIntersecting,
      intersectionRatio: ref.intersectionRatio
      );

      // console.log("Inview:", inView, ref);

      >
      ( inView, ref ) => (
      <div ref=ref style= position: "sticky", top: "30%" >
      <SuccessStory
      isIntersecting=this.state.isIntersecting
      intersectionRatio=this.state.intersectionRatio
      currentY=this.state.currentY
      />
      </div>
      )
      </InView>
      </div>

      <InView
      threshold=[0.1, 0.2, 0.3, 0.4, 0.6, 0.75, 0.8]
      onChange=(inView, ref) =>
      if (ref.intersectionRatio > 0.1)
      this.setState(
      currentYSecondText: ref.boundingClientRect.y,
      isIntersectingSecondText: ref.isIntersecting,
      intersectionRatioSecondText: ref.intersectionRatio
      );

      // console.log("Inview:", inView, ref);

      >
      ( inView, ref ) => (
      <div ref=ref>
      <SuccessStoryText2
      isIntersecting=this.state.isIntersectingSecondText
      intersectionRatio=this.state.intersectionRatioSecondText
      currentY=this.state.currentYSecondText
      />
      </div>
      )
      </InView>
      </div>
      );


      //
      export default SecondPage;




      And here is Css which I am using for the animations:



      .story-appear-scroll-down 
      animation: successStoryTextAppearScrollDown 0.3s linear;
      animation-fill-mode: forwards;


      @keyframes successStoryTextAppearScrollDown
      from
      transform: translate3d(0, 60px, 0);

      to
      transform: translate3d(0, 0, 0);



      .story-disappear-scroll-down
      animation: successStoryTextDisappearScrollDown 0.3s linear;
      animation-fill-mode: forwards;


      @keyframes successStoryTextDisappearScrollDown
      from
      transform: translate3d(0, 0, 0);

      to
      transform: translate3d(0, 0, 0);



      .story-appear-scroll-up
      animation: successStoryTextAppearScrollUp 0.3s linear;
      animation-fill-mode: forwards;


      @keyframes successStoryTextAppearScrollUp
      from
      transform: translate3d(0, 0, 0);

      to
      transform: translate3d(0, 0, 0);



      .story-disappear-scroll-up
      animation: successStoryTextDisappearScrollUp 0.3s linear;
      animation-fill-mode: forwards;


      @keyframes successStoryTextDisappearScrollUp
      from
      transform: translate3d(0, 0, 0);

      to
      transform: translate3d(0, 60px, 0);




      I was thinking what would be correct way to activate this kind of animation which I am trying to replicate and it would look the same every time it is activated (as in Apple webpage). As I already have spent too much time on this, however, I am not able to get the results that I want.



      I appreciate your help, and any tips or suggestions are welcome as this is my first post.







      javascript html reactjs css-animations intersection-observer






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 22:25









      Rotemya

      1,5985 gold badges17 silver badges27 bronze badges




      1,5985 gold badges17 silver badges27 bronze badges










      asked Mar 25 at 21:31









      r.Dier.Die

      63 bronze badges




      63 bronze badges






















          0






          active

          oldest

          votes










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346706%2freplicating-transition-based-on-intersection-observer%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346706%2freplicating-transition-based-on-intersection-observer%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript