<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: angelina-white</title>
    <description>The latest articles on Forem by angelina-white (@angelinawhite).</description>
    <link>https://forem.com/angelinawhite</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F859560%2F0089ffc9-0291-463c-8e1a-d2b4028be489.png</url>
      <title>Forem: angelina-white</title>
      <link>https://forem.com/angelinawhite</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/angelinawhite"/>
    <language>en</language>
    <item>
      <title>Draggable elements between two lists</title>
      <dc:creator>angelina-white</dc:creator>
      <pubDate>Fri, 15 Jul 2022 15:40:53 +0000</pubDate>
      <link>https://forem.com/angelinawhite/draggable-elements-between-two-lists-34h8</link>
      <guid>https://forem.com/angelinawhite/draggable-elements-between-two-lists-34h8</guid>
      <description>&lt;p&gt;This is for a basic dragging and dropping capability in between two set spots. &lt;/p&gt;

&lt;h2&gt;
  
  
  Helpful resources
&lt;/h2&gt;

&lt;p&gt;This is the &lt;a href="https://greensock.com/docs/v3/Plugins/Draggable"&gt;documentation&lt;/a&gt; for GSAP draggable, which is what I used. I also watched this &lt;a href="https://www.youtube.com/watch?v=WXHW_iGu8pc&amp;amp;t=225s"&gt;Youtube tutorial&lt;/a&gt; by Wael Yasmina that was helpful in getting an idea for what you're able to do with this function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kRntsJPB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pzd5hi17wqk0r191wzd1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kRntsJPB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pzd5hi17wqk0r191wzd1.png" alt="Image description" width="880" height="427"&gt;&lt;/a&gt;&lt;br&gt;
I found this &lt;a href="https://codepen.io/stevewojcik/pen/LeOVRK"&gt;CodePen&lt;/a&gt; by Steve Wojcik and worked from there. I wanted to get familiar with the basics so I removed a lot of extra features that was in it like dropShadow, dragGroup, and highlight. I tested each section to see if it would effect the main drag and drop function, and if it didn't, I just removed it. This also helped get an idea for what different parts do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Imports
&lt;/h2&gt;

&lt;p&gt;I used these scripts:&lt;br&gt;
&lt;code&gt;//cdnjs.cloudflare.com/ajax/libs/gsap/1.17.0/utils/Draggable.min.js&lt;/code&gt;&lt;br&gt;
&lt;code&gt;//cdnjs.cloudflare.com/ajax/libs/gsap/1.19.1/TweenMax.min.js&lt;/code&gt;&lt;br&gt;
&lt;code&gt;//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  HTML
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div id="container" class="container"&amp;gt;
  &amp;lt;h1 id="list1"&amp;gt;List 1&amp;lt;/h1&amp;gt;
  &amp;lt;h1 id="list2"&amp;gt;List 2&amp;lt;/h1&amp;gt;

  &amp;lt;div id="dropArea"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;div id="dropArea2"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;div id="dropArea3"&amp;gt;&amp;lt;/div&amp;gt;

  &amp;lt;div class="first"&amp;gt;
    &amp;lt;h3&amp;gt;1&amp;lt;/h3&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div class="second"&amp;gt;
    &amp;lt;h3&amp;gt;2&amp;lt;/h3&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div class="third"&amp;gt;
    &amp;lt;h3&amp;gt;3&amp;lt;/h3&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;container: the boundary&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;lists: just the titles and will not be used&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;drop areas: where the boxes will drop under list 2&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;first/second/third: the draggable boxes&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  CSS
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container
{
  position: absolute;
  margin: auto;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 400px;
  height: 330px;
  border-radius: 3px;
  border-style: solid;
  border-color: #fed3c1;
  border-width: 2px;
}

#list1 {
  margin-left: 100px;
  position: relative;
  margin-top: 35px;
}

#list2 {
  margin-left: 230px;
  position: absolute;
  margin-top: -58px;
}

.first
{
  position: absolute;
  top: 0px;
  left: 0px;
  width: 50px;
  height: 50px;
  background-color: pink;
  top: 100px;
  left: 106px;
  text-align: center;
}

#dropArea
{
  position: absolute;
  top: 100px;
  left: 242px;
  width: 50px;
  height: 50px;
}

.second
{
  position: absolute;
  top: 0px;
  left: 0px;
  width: 50px;
  height: 50px;
  background-color: pink;
  top: 175px;
  left: 105px;
  text-align: center;
}

#dropArea2
{
  position: absolute;
  top: 175px;
  left: 242px;
  width: 50px;
  height: 50px;
}

.third
{
  position: absolute;
  top: 0px;
  left: 0px;
  width: 50px;
  height: 50px;
  background-color: pink;
  top: 250px;
  left: 105px;
  text-align: center;
}

#dropArea3
{
  position: absolute;
  top: 250px;
  left: 242px;
  width: 50px;
  height: 50px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I added background colors to everything while I was working with it so I could see exactly where everything was. I pretty much kept everything in the same place except when adding a new box, I made the start and finish lower. &lt;/p&gt;

&lt;h2&gt;
  
  
  Javascript
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var dropArea = "#dropArea";
var overlapThreshold = "60%";

Draggable.create(".first", 
{
  bounds: "#container",
  onDrag: function(e) 
  {
      TweenLite.to(".first", 0.2, 
      {
        scaleX:1.10,
        scaleY:1.10
      });
  },
  onDragEnd: function(e) 
  {
    if (this.hitTest(dropArea, overlapThreshold)) 
    {
      TweenLite.to(this.target, 0.2, 
      {
        x: 136,
        y: 0,
        scaleX:1,
        scaleY:1
      });
    } 
    else 
    {
      TweenLite.to(this.target, 0.2, 
      {
        x: 0,
        y: 0,
        scaleX:1,
        scaleY:1
      });
    }
  }
});


var dropArea2 = "#dropArea2";
var overlapThreshold = "60%";

Draggable.create(".second", 
{
  bounds: "#container",
  onDrag: function(e) 
  {
      TweenLite.to(".second", 0.2, 
      {
        scaleX:1.10,
        scaleY:1.10
      });
  },
  onDragEnd: function(e) 
  {
    if (this.hitTest(dropArea2, overlapThreshold)) 
    {
      TweenLite.to(this.target, 0.2, 
      {
        x: 136,
        y: 0,
        scaleX:1,
        scaleY:1
      });
    } 
    else 
    {
      TweenLite.to(this.target, 0.2, 
      {
        x: 0,
        y: 0,
        scaleX:1,
        scaleY:1
      });
    }
  }
});


var dropArea3 = "#dropArea3";
var overlapThreshold = "60%";

Draggable.create(".third", 
{
  bounds: "#container",
  onDrag: function(e) 
  {
      TweenLite.to(".third", 0.2, 
      {
        scaleX:1.10,
        scaleY:1.10
      });
  },
  onDragEnd: function(e) 
  {
    if (this.hitTest(dropArea3, overlapThreshold)) 
    {
      TweenLite.to(this.target, 0.2, 
      {
        x: 136,
        y: 0,
        scaleX:1,
        scaleY:1
      });
    } 
    else 
    {
      TweenLite.to(this.target, 0.2, 
      {
        x: 0,
        y: 0,
        scaleX:1,
        scaleY:1
      });
    }
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This has the same code base three times, one for each box. I just changed the variable names to reflect where the box should land. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;bound: this is where you put the container you want to keep your draggable item in&lt;/li&gt;
&lt;li&gt;onDrag: when the box is being dragged, it will look slightly bigger&lt;/li&gt;
&lt;li&gt;onDragEnd: If the box is placed in the dropArea, it will stay there, else, it will go back to its original position under List 1&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>gsap</category>
    </item>
    <item>
      <title>Simple Homemade Loading Screen in React</title>
      <dc:creator>angelina-white</dc:creator>
      <pubDate>Fri, 24 Jun 2022 14:40:53 +0000</pubDate>
      <link>https://forem.com/angelinawhite/simple-homemade-loading-screen-in-react-250c</link>
      <guid>https://forem.com/angelinawhite/simple-homemade-loading-screen-in-react-250c</guid>
      <description>&lt;h2&gt;
  
  
  Reference tutorial
&lt;/h2&gt;

&lt;p&gt;In my last blog, I mentioned this &lt;a href="https://www.youtube.com/watch?v=SR8755C0bME"&gt;tutorial&lt;/a&gt; by Tony Heimark that is super easy to follow. I'll be going off of that, but making the animation instead. He uses the package, &lt;a href="https://www.npmjs.com/package/react-spinners"&gt;react-spinners&lt;/a&gt;. Instead of that, I'll be using the flower icon I found off of flaticon.com. &lt;/p&gt;

&lt;h2&gt;
  
  
  Finding an image
&lt;/h2&gt;

&lt;p&gt;I went into google and typed in "flower icon". I went to &lt;a href="https://www.flaticon.com/free-icon/flower_346167?term=flower&amp;amp;page=1&amp;amp;position=1&amp;amp;page=1&amp;amp;position=1&amp;amp;related_id=346167&amp;amp;origin=tag"&gt;flaticon.com&lt;/a&gt;. I just right clicked the image for the image address. This gives an image with no background.&lt;/p&gt;

&lt;h2&gt;
  
  
  App.js
&lt;/h2&gt;

&lt;p&gt;In App.js, I made a useEffect with a setTimeout inside. This will be how long the screen is loading for. This will load for 5 seconds.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const [loading, setLoading] = useState(false);
  useEffect(() =&amp;gt;
  {
    setLoading(true)
    setTimeout(() =&amp;gt;
    {
      setLoading(false)
    }, 5000)
  }, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Under return, I made a ternary statement with the loading state. If loading is true, show the loading screen. If loading is false, show the homepage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  return (
    &amp;lt;div class="App"&amp;gt;
      {loading ? 
        &amp;lt;Flower /&amp;gt;
      :
      &amp;lt;div class="homePage"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I made a separate component for the loading screen called, "Flower".&lt;/p&gt;

&lt;h2&gt;
  
  
  Flower.js
&lt;/h2&gt;

&lt;p&gt;In Flower.js, I made a useEffect with the animation inside it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  useEffect(() =&amp;gt;
  {
     gsap.to("#flower", 1.75, 
     {
        y: 75,
        yoyo: true,
        repeat: -1, 
        ease: "power1",
     });
 }, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This animation makes the flower float up and down. 1.75 is the amount of time for the animation. The "y" makes it move up 75 pixels. The yoyo being true means the flower will yoyo up and down 75 pixels. The repeat being -1 means it will repeat forever. The ease is the kind of style it is moving. &lt;/p&gt;

&lt;p&gt;Under return, I added the image and a tag that says it's loading.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  return (
    &amp;lt;div class="loadingScreen"&amp;gt;
        &amp;lt;img className="bus" src="https://t4.ftcdn.net/jpg/01/76/26/25/360_F_176262588_5UBYLDB9mqLxdqavixo0d4XF4g6ydFpZ.jpg" /&amp;gt;
        &amp;lt;h1 id="loadingText"&amp;gt;Loading...&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I was playing around with it, and another animation idea would be for the flower to spin.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gsap.to("#flower", 2, 
{
    rotation: 360,
    repeat: -1, 
    ease: "slow",
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This just rotates the flower 360 degrees forever with a "slow" style. &lt;/p&gt;

</description>
      <category>react</category>
      <category>gsap</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Animation Finds for React</title>
      <dc:creator>angelina-white</dc:creator>
      <pubDate>Thu, 02 Jun 2022 17:28:29 +0000</pubDate>
      <link>https://forem.com/angelinawhite/animation-finds-for-react-4a93</link>
      <guid>https://forem.com/angelinawhite/animation-finds-for-react-4a93</guid>
      <description>&lt;p&gt;I've been working on a recipe saver app in React and using it to learn how to implement different animations with GSAP. These are the animations I've learned so far and how to do them. Some also include the tutorials I've found for them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Horizontally moving title into place&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fading page in&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Loading screen&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Horizontally scroll through images&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using ScrollTrigger to move images from left and right&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Using GSAP in React
&lt;/h2&gt;

&lt;p&gt;1: Install GSAP into React.&lt;br&gt;
&lt;code&gt;npm i gsap&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2: Import GSAP at the top of the page.&lt;br&gt;
&lt;code&gt;import { gsap } from "gsap";&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3: In Index.js, I removed the lines with strict mode in order for the animations to work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;React.StrictMode&amp;gt;
  &amp;lt;/React.StrictMode&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4: Add the hooks you are using&lt;br&gt;
&lt;code&gt;import { useEffect, useState } from "react";&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Horizontal Movement
&lt;/h2&gt;

&lt;p&gt;This will make the title move into place from the right whenever the page is started. This will be done in Home.js.&lt;/p&gt;

&lt;p&gt;1: In the return section, create an h1 tag with the page title and an id. That id is what I used for the tween.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
   &amp;lt;h1 id="homeTitle"&amp;gt;Home&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2: Before the return, create a useEffect() hook&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt;
  {
  }, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3: In useEffect(), create a tween with the "homeTitle" id. This will make the title move into place from 50 pixels to the right.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gsap.from("#homeTitle", {x: 50, duration: 1})&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Page Fade In
&lt;/h2&gt;

&lt;p&gt;This will fade in the page when the app is started. This will all be done in App.js.&lt;/p&gt;

&lt;p&gt;1: In the return section, I put a div with a class. That class is what I used for the tween. The contents of the entire page will go into this div.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
   &amp;lt;div className="homePage"&amp;gt;
   &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2: Before the return, create a useEffect() hook&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; useEffect(() =&amp;gt;
  {
  }, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3: In useEffect(), create a tween with the "homePage" class. If you would like the fade to be longer, change the duration to a higher number. This tween is starting &lt;em&gt;from&lt;/em&gt; the opacity of 0 so it will fade in from blank.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gsap.from(".homePage", {duration: 1, opacity: 0});&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Loading
&lt;/h2&gt;

&lt;p&gt;To find out one way to make a loading screen, I followed this easy to follow &lt;a href="https://www.youtube.com/watch?v=SR8755C0bME"&gt;tutorial&lt;/a&gt; on YouTube by Tony Heimark. He used the package, &lt;a href="https://www.npmjs.com/package/react-spinners"&gt;react-spinners&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can make this loading screen as long as it takes to load your data. My data is 5 very simple recipes so I put it in a setTimeout hook to see it more as Heimark shows. This will all be done in App.js.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using react-spinners&lt;/strong&gt;&lt;br&gt;
1: Install the package.&lt;br&gt;
&lt;code&gt;npm install --save react-spinners&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2: Find which loader you like on the &lt;a href="https://www.davidhu.io/react-spinners/"&gt;demo page&lt;/a&gt;. I chose SyncLoader.&lt;/p&gt;

&lt;p&gt;3: At the top of App.js import your loader.&lt;br&gt;
&lt;code&gt;import SyncLoader from "react-spinners/SyncLoader";&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before the return&lt;/strong&gt;&lt;br&gt;
1: Create a state that shows whether "loading" is true or false.&lt;br&gt;
&lt;code&gt;const [loading, setLoading] = useState(false);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2: Create a useEffect() hook underneath the loading state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; useEffect(() =&amp;gt;
  {
  }, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3: In useEffect(), set loading to be true. &lt;br&gt;
&lt;code&gt;setLoading(true)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;4: In the useEffect() after setting loading to true, add a setTimeout() hook. This is set to timeout after 5 seconds.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setTimeout(() =&amp;gt;
{
}, 5000)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5: In setTimeout() set loading to be false. After 5 seconds, loading will be set back to false.&lt;br&gt;
&lt;code&gt;setLoading(false)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In the return&lt;/strong&gt;&lt;br&gt;
1: Make a div that includes everything.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
   &amp;lt;div className="App"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2: In the "App" div, create a ternary expression with the loading state. &lt;br&gt;
&lt;code&gt;loading ? true : false&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3: Add the loader for when loading is true, and the page contents for when loading is false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{loading 
   ? 
   &amp;lt;div id="loader"&amp;gt;
      &amp;lt;SyncLoader color={"#FFB5D4"} loading={loading} size={30} /&amp;gt;
   &amp;lt;/div&amp;gt; 
   :
   &amp;lt;div className="homePage"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ScrollTrigger: Horizontal scrolling
&lt;/h2&gt;

&lt;p&gt;I watched this &lt;a href="https://www.youtube.com/watch?v=X7IBa7vZjmo"&gt;video&lt;/a&gt; made by GSAP that explains the different parts of ScrollTrigger and what you can do. You can find a lot of different &lt;a href="https://greensock.com/st-demos/"&gt;examples&lt;/a&gt; on their website. For horizontal scrolling, I followed this &lt;a href="https://codepen.io/GreenSock/pen/YzygYvM"&gt;example&lt;/a&gt;. Instead of sections, I used images.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Home.js&lt;/strong&gt;&lt;br&gt;
1: In return, add 3 images with the same class name. I won't include the image sources here to not take up too much space. Instead of images, you can use colored sections to see the movement also.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img className="panel" src="" /&amp;gt;
&amp;lt;img className="panel" src="" /&amp;gt;
&amp;lt;img className="panel" src="" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2: Before the return, create a useEffect() hook&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; useEffect(() =&amp;gt;
  {
  }, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3: Add animation defaults to the top of the useEffect()&lt;br&gt;
&lt;code&gt;gsap.defaults({ease: "none", duration: 2});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;4: Create an array with the panels&lt;br&gt;
&lt;code&gt;let sections = gsap.utils.toArray(".panel");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;5: Create a tween that scrolls through the array horizontally&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gsap.to(sections, {
   xPercent: -100 * (sections.length - 1),
   ease: "none",
   scrollTrigger: {
      trigger: ".cont",
      pin: true,
      scrub: 1,
      snap: 1 / (sections.length - 1),
      end: "+=3500",
   }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;App.css&lt;/strong&gt;&lt;br&gt;
1: I made the image the size of the screen&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.panel {
  height: 100vh;
  width: 100%;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ScrollTrigger: Images from left and right
&lt;/h2&gt;

&lt;p&gt;This will move an image from the left and another image from the right as you scroll. The other images will sit in place while the animated images move over them. This will be done in Home.js. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Home.js&lt;/strong&gt;&lt;br&gt;
1: In return, add 6 images. I included a class for each image. I also made a box class that makes the dimensions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img className="imageA box" src="" /&amp;gt;
&amp;lt;img className="imageB box" src="" /&amp;gt;
&amp;lt;img className="imageC box" src="" /&amp;gt;
&amp;lt;img className="imageD box" src="" /&amp;gt;
&amp;lt;img className="imageE box" src="" /&amp;gt;
&amp;lt;img className="imageF box" src="" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2: Before the return, create a useEffect() hook&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; useEffect(() =&amp;gt;
  {
  }, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3: Add animation defaults to the beginning of the useEffect()&lt;br&gt;
&lt;code&gt;gsap.defaults({ease: "none", duration: 2});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;4: Create a tween with the horizontal movement. This will move the image into full view from the left.&lt;br&gt;
&lt;code&gt;gsap.from(".imageA", {x: -1700})&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;5: Inside the tween, create a scrollTrigger object. The &lt;em&gt;trigger&lt;/em&gt; point for when the image will start moving is when the top of the screen touches the top of the image. The image will be &lt;em&gt;pinned&lt;/em&gt; into place once the movement is done. The &lt;em&gt;scrub&lt;/em&gt; being true means the scroll will control where the image is at depending on how far you are scrolled. If the scrub was false, the image would animate and move on its own once it is triggered.&lt;br&gt;
The entire tween will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gsap.from(".imageA", {
   scrollTrigger:
   {
      trigger: ".imageA",
      start: "top top",
      pin: true,
      scrub: true,
   }, x: -1700
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;6: I added another tween for moving another image. This will move an image from the right.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gsap.from(".imageD", {
   scrollTrigger:
   {
      trigger: ".imageD",
      start: "top top",
      pin: true,
      scrub: true,
   }, x: 1700
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;App.css&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I made the image the size of the screen.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.box {
   height: 100vh;
   width: 100%;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2: For the animated images, I made the animated images have a position of absolute in order to move over the other images set in place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.imageA {
  position: absolute;
}

.imageD {
  position: absolute;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>react</category>
      <category>gsap</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Exploring Web Animations</title>
      <dc:creator>angelina-white</dc:creator>
      <pubDate>Wed, 11 May 2022 23:17:14 +0000</pubDate>
      <link>https://forem.com/angelinawhite/exploring-web-animations-55pl</link>
      <guid>https://forem.com/angelinawhite/exploring-web-animations-55pl</guid>
      <description>&lt;h2&gt;
  
  
  Is it even worth it
&lt;/h2&gt;

&lt;p&gt;I've always wondered how animations are done on websites. I thought this would be so cool to learn, but I was also doubtful about how much of it I would actually use. I did a brief search on what was possible and found instructions on how to make words go big then small, and how to make a newspaper rectangle spin and get smaller until it's gone. I dismissed this idea thinking there is probably something more practical I can learn.&lt;/p&gt;

&lt;p&gt;Another day, I gave animations another shot and came across this &lt;a href="https://yalantis.com/blog/web-animation-technologies-and-tools/"&gt;article&lt;/a&gt;. It showed examples of really cool things you can do: loading, welcoming, scrolling, image galleries, and visual feedback. It also included different libraries, which helped clear up how mysterious where animations come from is. I looked up more libraries and found even more: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://greensock.com"&gt;GreenSock (GSAP)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://scrollmagic.io"&gt;ScrollMagic&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://velocityjs.org"&gt;Velocity.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mojs.github.io"&gt;mo.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://animejs.com"&gt;anime.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://maxwellito.github.io/vivus/"&gt;vivus.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://popmotion.io"&gt;Popmotion&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://threejs.org"&gt;three.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://scrollrevealjs.org"&gt;scrollReveal.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kristofferandreasen.github.io/wickedCSS/"&gt;WickedCSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/shakrmedia/tuesday"&gt;tuesday&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://elrumordelaluz.github.io/csshake/"&gt;CSShake&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/bendc/animateplus"&gt;Animate Plus&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tictail/bounce.js/blob/master/README.md"&gt;Bounce.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ianlunn.github.io/Hover/"&gt;Hover.css&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are so many libraries I am overwhelmed. Some seem like they were more oriented towards doing a specialization while others were larger libraries with more options.&lt;/p&gt;

&lt;p&gt;I looked up what library people prefer to use, and I found GSAP mentioned a lot so I decided to roll with it. It has a lot of capabilities, and you can also include plugins that do more specific tasks. It seems like I would be able to do a lot of different things with this library if I learned how to use it. There is a lot of documentation with examples of code, visual examples of how the animation looks, and Youtube tutorial videos. They also show a lot of amazing things people have &lt;a href="https://greensock.com/showcase/"&gt;created&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using GSAP
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Animation ultimately boils down to changing property values many times per second, making something appear to move, fade, spin, etc. GSAP snags a starting value, an ending value and then interpolates between them 60 times per second.” -&lt;a href="https://greensock.com/get-started/"&gt;Getting Started with GSAP&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To include GSAP, add this code to your HTML file before you include your JavaScript file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/gsap.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="index.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A &lt;strong&gt;tween&lt;/strong&gt; is one of the foundations of GSAP. It is basically a line of code with information about how you want to animate an object. Here is their example of what a tween looks like:&lt;br&gt;
&lt;code&gt;gsap.to(".box", {rotation: 27, x: 100, duration: 1});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I copied and pasted tweens from GSAP documentation into &lt;a href="https://codepen.io/trending"&gt;CodePen&lt;/a&gt;, and played around with how the code worked. Every example I show here is from the GSAP documentation JavaScript examples. Some things I changed to match the HTML I made. Here is the first animation I copied, which is &lt;strong&gt;text fading&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Html:&lt;br&gt;
&lt;code&gt;&amp;lt;h1&amp;gt;Hello World&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;JavaScript:&lt;br&gt;
&lt;code&gt;gsap.to("h1", {duration: 5, opacity: 0.3});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is a .to() method. The duration is how long it takes to get &lt;em&gt;to&lt;/em&gt; that opacity so the opacity starts at 1.0 and goes to 0.3. There are also the .from() and .fromTo() methods. Here is the same example, but with the .from() method. &lt;/p&gt;

&lt;p&gt;JavaScript:&lt;br&gt;
&lt;code&gt;gsap.from("h1", {duration: 5, opacity: 0.3});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The duration is how long it takes to get &lt;em&gt;from&lt;/em&gt; that opacity so the opacity starts at 0.3 and goes to 1.0.&lt;/p&gt;

&lt;p&gt;Here is an example for basic &lt;strong&gt;movement horizontally and vertically&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;move left:&lt;/em&gt;&lt;br&gt;
&lt;code&gt;gsap.to("h1", {duration: 1, x: -100});&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;move right:&lt;/em&gt;&lt;br&gt;
&lt;code&gt;gsap.to("h1", {duration: 1, x: 100});&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;move up:&lt;/em&gt;&lt;br&gt;
&lt;code&gt;gsap.to("h1", {duration: 1, y: -100});&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;move down:&lt;/em&gt;&lt;br&gt;
&lt;code&gt;gsap.to("h1", {duration: 1, y: 100});&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*The y: -100 to move up and y: 100 to move down are not typos. It is negative to go up.&lt;/p&gt;

&lt;p&gt;Here is an example of how to make things move in a &lt;strong&gt;sequence&lt;/strong&gt;. Whichever line in the JavaScript comes first will move first in this example:&lt;/p&gt;

&lt;p&gt;HTML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;First Movement&amp;lt;/h1&amp;gt;
&amp;lt;h2&amp;gt;Second Movement&amp;lt;/h2&amp;gt;
&amp;lt;h3&amp;gt;Third Movement&amp;lt;/h3&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var tl = gsap.timeline({repeat: 30, repeatDelay: 1});
tl.to("h1", {duration: 1, x: 200});
tl.to("h2", {duration: 1, x: 200, scale: 0.2});
tl.to("h3", {duration: 1, x: 200, scale: 2, y: 20});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When putting in properties, they have to be in camelCase. For example, for "font-size" you would put "fontSize". This is an example with &lt;strong&gt;many properties&lt;/strong&gt;. I played around with each property trying to figure out what they do.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gsap.to("h1", 2, 
{
    scale: 0.1, 
    y: 60,
    yoyo: true, 
    repeat: -1, 
    ease: "power1.inOut",
    delay:1,
    stagger: 
    {
      amount: 1.5, 
      grid: "auto",
      from: "center"
    }
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes the text yoyo back and forth from the top left towards the bottom right of the screen&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;gsap.to("h1", 2&lt;/em&gt; : The 2 is the duration. Apparently, you don't need to specify "duration" here. &lt;/li&gt;
&lt;li&gt;
&lt;em&gt;scale: 0.1&lt;/em&gt; : The scale is the size of the text.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;yoyo: true&lt;/em&gt; : When I made yoyo false, the text did not move back to where it initially started.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;repeat: -1&lt;/em&gt; : This makes the movement repeat infinitely. I made repeat a positive 1, and the movement only repeated one time. &lt;/li&gt;
&lt;li&gt;
&lt;em&gt;ease: "power1.inOut"&lt;/em&gt; : The ease is the style of the movement. There are different options like elastic, bounce, and sine. There is a &lt;a href="https://greensock.com/get-started/"&gt;visual display&lt;/a&gt; if you scroll down to the "Easing" section of how each ease works with a graph of how fast the movement is for each. &lt;/li&gt;
&lt;li&gt;
&lt;em&gt;delay:1&lt;/em&gt; : Delay is how long until the movement starts.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;stagger&lt;/em&gt; : The amount of stagger is how long the text stays at that point in between each yoyo. I'm not entirely sure what the "grid" and "from" do at this point.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the code I made for a &lt;strong&gt;color changing&lt;/strong&gt; background gif I wanted to use as the header image for this post. I published it, and instead of the colors fading, the colors were shattering so I replaced it with just an image.&lt;/p&gt;

&lt;p&gt;CSS:&lt;br&gt;
&lt;code&gt;background-color: #F8D6FF;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ar tl = gsap.timeline({repeat: 3});

tl.to("h1", 
{
  duration: 1, 
  backgroundColor: "#F8D6FF"
});

tl.to("h1", 
{
  duration: 2,
  backgroundColor: "#D8C3E8"
});

tl.to("h1", 
{
  duration: 2,
  backgroundColor: "#E9E1FE"
});

tl.to("h1", 
{
  duration: 2,
  backgroundColor: "#C3C3E8"
});

tl.to("h1", 
{
  duration: 2,
  backgroundColor: "#D6E1FF"
});

tl.to("h1", 
{
  duration: 1, 
  backgroundColor: "#F8D6FF"
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It creates a sequence of transitions from one color to the next, starting with the original background color from the CSS file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Looking Forward
&lt;/h2&gt;

&lt;p&gt;These are the first steps to learning how to make fun visualizations. GSAP also has &lt;a href="https://greensock.com/react"&gt;information&lt;/a&gt; on how to incorporate it in React. We will be learning that soon so I will have to take a look at that as well. I'm going to start looking into more of their recommendations on what I should know and utilizing their plugins. Eventually, I'd also like to branch out and see how to use other libraries.&lt;/p&gt;

</description>
      <category>gsap</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
