<?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>DEV Community: ksbisht</title>
    <description>The latest articles on DEV Community by ksbisht (@ksbisht941).</description>
    <link>https://dev.to/ksbisht941</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%2F388448%2F4d860945-eab9-47e7-ab3a-c31c0fc1c752.jpeg</url>
      <title>DEV Community: ksbisht</title>
      <link>https://dev.to/ksbisht941</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ksbisht941"/>
    <language>en</language>
    <item>
      <title>Horizontal Scrolling Animation using GSAP and ScrollTrigger.</title>
      <dc:creator>ksbisht</dc:creator>
      <pubDate>Tue, 11 May 2021 04:56:44 +0000</pubDate>
      <link>https://dev.to/ksbisht941/horizontal-scrolling-animation-using-gsap-and-scrolltrigger-n3f</link>
      <guid>https://dev.to/ksbisht941/horizontal-scrolling-animation-using-gsap-and-scrolltrigger-n3f</guid>
      <description>&lt;p&gt;We love animation. In the animated movies, video games, advertisements, etc. but here we are going to create a horizontal scrolling animation using GSAP and ScrollTrigger. As you guess by reading the title. So let’s get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Matching the look
&lt;/h2&gt;

&lt;p&gt;The first thing I want to do with this component is to match the design. probably this will be the easiest part since there are no complicated graphics that will need &lt;code&gt;SVG&lt;/code&gt; or icons.&lt;/p&gt;

&lt;p&gt;Inside our component, I will start by creating the markup for the animation. The markup design divides into two sections, first design the very simple landing that appear at the first sight of the page and the second section appears on scrolling the page.&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;div class="demo-wrapper"&amp;gt;
      &amp;lt;header class="df aic jcc"&amp;gt;
        &amp;lt;div&amp;gt;
          &amp;lt;h1&amp;gt;ScrollTrigger&amp;lt;/h1&amp;gt;
          &amp;lt;h2&amp;gt;demo&amp;lt;/h2&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/header&amp;gt;
      &amp;lt;section class="demo-text"&amp;gt;
        &amp;lt;div class="wrapper text"&amp;gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&amp;lt;/div&amp;gt;
      &amp;lt;/section&amp;gt;
      &amp;lt;section class="demo-gallery"&amp;gt;
        &amp;lt;ul class="wrapper"&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;img
              height="317"
              src="https://source.unsplash.com/random/450x317?sig=128"
              width="450"
            /&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;img
              height="317"
              src="https://source.unsplash.com/random/450x317?sig=10"
              width="450"
            /&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;img
              height="317"
              src="https://source.unsplash.com/random/450x317?sig=91"
              width="450"
            /&amp;gt;
          &amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
      &amp;lt;/section&amp;gt;
      &amp;lt;section class="demo-gallery"&amp;gt;
        &amp;lt;ul class="wrapper"&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;img
              height="317"
              src="https://source.unsplash.com/random/450x317?sig=12"
              width="450"
            /&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;img
              height="317"
              src="https://source.unsplash.com/random/450x317?sig=20"
              width="450"
            /&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;img
              height="317"
              src="https://source.unsplash.com/random/450x317?sig=145"
              width="450"
            /&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;img
              height="317"
              src="https://source.unsplash.com/random/450x317?sig=22"
              width="450"
            /&amp;gt;
          &amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
      &amp;lt;/section&amp;gt;
      &amp;lt;section class="demo-gallery"&amp;gt;
        &amp;lt;ul class="wrapper"&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;img
              height="317"
              src="https://source.unsplash.com/random/450x317?sig=61"
              width="450"
            /&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;img
              height="317"
              src="https://source.unsplash.com/random/450x317?sig=70"
              width="450"
            /&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;img
              height="317"
              src="https://source.unsplash.com/random/450x317?sig=112"
              width="450"
            /&amp;gt;
          &amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
      &amp;lt;/section&amp;gt;
      &amp;lt;section class="demo-gallery"&amp;gt;
        &amp;lt;ul class="wrapper"&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;img
              height="317"
              src="https://source.unsplash.com/random/450x317?sig=88"
              width="450"
            /&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;img
              height="317"
              src="https://source.unsplash.com/random/450x317?sig=35"
              width="450"
            /&amp;gt;
          &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;
            &amp;lt;img
              height="317"
              src="https://source.unsplash.com/random/450x317?sig=92"
              width="450"
            /&amp;gt;
          &amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
      &amp;lt;/section&amp;gt;
      &amp;lt;section class="demo-text"&amp;gt;
        &amp;lt;div class="wrapper text"&amp;gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&amp;lt;/div&amp;gt;
      &amp;lt;/section&amp;gt;
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Styling!
&lt;/h2&gt;

&lt;p&gt;I know the page is looking ugly right now, let’s change that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
  font-size: 16px;
}
@media (max-width: 500px) {
  :root {
    font-size: 14px;
  }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

::-moz-selection {
  background: #87cd33;
  color: white;
}

::selection {
  background: #87cd33;
  color: white;
}

body {
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial,
    sans-serif, Apple Color Emoji, Segoe UI Emoji;
}

h1 {
  font-size: 5rem;
}
h2 {
  font-size: 2rem;
}

img {
  width: 100%;
  height: auto;
  background: #f0f0f0;
}

ul {
  padding-left: 1rem;
  list-style: none;
}

li {
  flex-shrink: 0;
  width: clamp(500px, 30vw, 800px);
  padding-right: 1rem;
}

header {
  height: 100vh;
}
footer {
  height: 50vh;
}

:-webkit-any-link {
  color: #4e9815;
}

:-moz-any-link {
  color: #4e9815;
}

:any-link {
  color: #4e9815;
}

.df {
  display: flex;
}
.aic {
  align-items: center;
}
.jcc {
  justify-content: center;
}

.loader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: black;
  color: white;
}

.demo-wrapper {
  overflow-x: hidden;
}

.wrapper {
  display: flex;
}

.demo-gallery:not(.last) {
  padding-bottom: 1rem;
}

.demo-text .text {
  font-size: clamp(8rem, 15vw, 16rem);
  line-height: 1;
  font-weight: 900;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the final look of our page after styling!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpqk9o4ffgdylidde04mf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpqk9o4ffgdylidde04mf.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Time To Logic
&lt;/h2&gt;

&lt;p&gt;First, we need to include GSAP and ScrollTrigger in our project, for this example, we will use the &lt;code&gt;unpkg&lt;/code&gt;, this needs to be added in the HTML inside a &lt;code&gt;script&lt;/code&gt; tag.&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://unpkg.co/gsap@3/dist/gsap.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="https://unpkg.com/imagesloaded@4/imagesloaded.pkgd.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="https://unpkg.com/gsap@3/dist/ScrollTrigger.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s trigger the animation when we scroll our web page. By using this script.&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&amp;gt;
      gsap.registerPlugin(ScrollTrigger);
      const images = gsap.utils.toArray("img");
      const showDemo = () =&amp;gt; {
        document.body.style.overflow = "auto";
        document.scrollingElement.scrollTo(0, 0);

        gsap.utils.toArray("section").forEach((section, index) =&amp;gt; {
          const w = section.querySelector(".wrapper");
          const [x, xEnd] =
            index % 2
              ? ["100%", (w.scrollWidth - section.offsetWidth) * -1]
              : [w.scrollWidth * -1, 0];
          gsap.fromTo(
            w,
            { x },
            {
              x: xEnd,
              scrollTrigger: {
                trigger: section,
                scrub: 0.5,
              },
            }
          );
        });
      };

      imagesLoaded(images).on("always", showDemo);
    &amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Congratulation! We did it. This is the final look at our web page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyciy0rqxjzcpdiatjpjm.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyciy0rqxjzcpdiatjpjm.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay guys, hope so you learn something new with me. By the way, this is my first blog ever. If you have any ideas on how to improve this I’d love to read them in the comments.&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;

</description>
      <category>gsap</category>
      <category>scrolltrigger</category>
      <category>javascript</category>
      <category>greensock</category>
    </item>
  </channel>
</rss>
