Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                    <section>
      <h3>algo</h3>
      <p>
        Lorem, ipsum dolor sit amet consectetur adipisicing elit. Soluta reiciendis non explicabo, accusamus debitis deleniti unde inventore nam aliquam corporis tempora, libero necessitatibus optio iure quis ipsa, nostrum itaque quam.
      </p>
    </section>
    <article class="panelContainer">
      <div id='pnl2012' class='panel'>
          <h3>2012</h3>
      </div>
      <div id='pnl2013' class='panel'>
        <h3>2013</h3>
      </div>
      <div id='pnl2014' class='panel'>
        <h3>2014</h3>
      </div>
      <div id='pnl2015' class='panel'>
        <h3>2015</h3>
      </div>
      <div id='pnl2016' class='panel'>
        <h3>2016</h3>
      </div>
      <div id='pnl2017' class='panel'>
        <h3>2017</h3>
      </div>
      <div id='pnl2018' class='panel'>
        <h3>2018</h3></div>
      <div id='pnl2019' class='panel'>
        <h3>2019</h3>
      </div>
      <div id='pnl2020' class='panel'>
        <h3>2020</h3>
      </div>
      <div id='pnl2021' class='panel'>
        <h3>2021</h3>
      </div>
      <div class="timeline">
        <div class="yearLineContainer">
          <div class="lineCenter"></div>
          <span id='id2012' class="yearLine" >2012</span>
          <span id='id2013' class="yearLine" >2013</span>
          <span id='id2014' class="yearLine" >2014</span>
          <span id='id2015' class="yearLine" >2015</span>
          <span id='id2016' class="yearLine" >2016</span>
          <span id='id2017' class="yearLine" >2017</span>
          <span id='id2018' class="yearLine" >2018</span>
          <span id='id2019' class="yearLine" >2019</span>
          <span id='id2020' class="yearLine" >2020</span>
          <span id='id2021' class="yearLine" >2021</span>
        </div>
      </div>
    </article>
    <h3>algo</h3>
    <p>
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Sit facere nam eos a ab fugit exercitationem vitae? Inventore veritatis dicta quisquam deserunt, quia fugiat magni nesciunt ipsum tempore sint, velit, dolore saepe nulla sunt hic. Natus eum laboriosam fugit non odit atque quod voluptate rerum, beatae voluptatem sunt necessitatibus similique dolorem ullam exercitationem dolorum aliquid accusamus eius, consectetur cumque minima et porro. Suscipit ullam a quidem assumenda veritatis enim unde tempora, mollitia expedita quasi aut cumque ducimus quis sit velit maxime? Tempore labore ea nisi laudantium deleniti in eligendi non. Pariatur ducimus quibusdam alias suscipit eius, vitae at eligendi, animi odio voluptatibus sed, nisi distinctio necessitatibus. Vero, quod enim dolorum unde illum minus pariatur aspernatur sint, voluptates maxime aliquid et assumenda quidem earum debitis voluptatum consequuntur sunt quos voluptatem. Maiores exercitationem officia eligendi hic dicta vel, modi fugit ad perferendis incidunt voluptas accusamus neque. Accusamus vel deleniti fugit libero, quos quae cumque ipsa ipsam, ratione, accusantium unde nostrum quasi deserunt enim. Porro, eius temporibus eos mollitia deleniti exercitationem praesentium et dolorum corporis itaque. Ab incidunt eveniet eius corporis blanditiis, tenetur est dicta libero dignissimos consectetur perspiciatis quam, molestiae voluptatibus ut quaerat saepe a. Quidem laborum nemo, odio tempora blanditiis aliquid quibusdam possimus dolore amet quae eligendi corrupti iusto distinctio provident nam quaerat quisquam dolorum officia facere obcaecati tenetur. Voluptatibus voluptatum nulla doloribus ratione adipisci ipsam sequi, placeat quos, aperiam quia consequuntur odit natus ex unde temporibus, asperiores et? Officia similique nam delectus cumque voluptate, omnis a dolor repellat totam? Saepe, ex, sequi explicabo repellendus ab quidem magni veritatis facere, laudantium dolores eaque. Numquam labore necessitatibus fuga voluptates assumenda! Beatae aliquam nobis quae amet debitis suscipit sapiente odit totam vel autem, facilis delectus, impedit minus error! Voluptates in tempore est ab dolor illo eos, pariatur expedita ad, recusandae amet quibusdam aut iste quae atque? Maxime voluptas, delectus sapiente itaque at id nobis mollitia, cum rem blanditiis temporibus atque, quae voluptatum consequuntur! Eius dicta, tempore nihil assumenda aperiam accusantium nobis earum? Quo voluptatum excepturi quidem laboriosam repudiandae, exercitationem odit at, fuga neque qui laborum quis iste ex nulla nisi nobis tempore vel sapiente incidunt recusandae? Esse assumenda sunt, aut harum alias suscipit debitis soluta libero, quod omnis totam animi odio aperiam numquam nam, maxime voluptate tenetur qui sed? Voluptate molestiae unde atque veniam corporis laborum? Adipisci, labore. Laborum quibusdam corporis iusto rem eius cupiditate, cumque necessitatibus, in omnis veniam, temporibus tempora recusandae consequuntur autem? Vitae consequuntur iure optio voluptatem facilis, atque est nostrum quod. Veniam incidunt nobis ut vero voluptatum iusto aliquid? Soluta quisquam et nam ad repellendus incidunt, iure odit laudantium recusandae officia, ullam delectus est eligendi cum? Aspernatur, praesentium. Alias beatae ipsum unde. Quod quasi ipsa fuga fugiat soluta nostrum cum voluptatum necessitatibus id aspernatur est corrupti expedita sunt facere tempore, suscipit aperiam provident nesciunt optio enim tenetur ex dicta. Consectetur necessitatibus cumque sequi rem consequatur perspiciatis vitae, sint voluptatibus nemo architecto veniam dolorem possimus minus non nesciunt, molestias placeat beatae officia sit? Odit sit necessitatibus consectetur deserunt nam labore!
    </p>
              
            
!

CSS

              
                * {
  margin: 0;
  overflow-x: hidden;
}
.panelContainer {
  width: 100vw;
  height: 100vh;
  margin: 0 auto;
  background-color: rgb(99, 76, 76);
  display: flex;
  align-items: center;
  overflow: hidden;
}
.panel {
  box-sizing: border-box;
  min-width: 100vw;
  height: 100vh;
  background-color: rgb(108, 148, 114);
  border-left: solid 3px #ffffff;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
/* === === ===TimeLine=== === === */
.timeline {
  border: solid 1px;
  display: flex;
  height: 50px;
  justify-content: center;
  background-color: rgb(50, 61, 85);
  position: fixed;
  bottom: 0;
  width: 100%;
  z-index: 100;
}

.yearLineContainer {
  width: 90%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  background-color: rgb(50, 61, 85);
  overflow-x: auto;
}

.yearLine {
  transform: rotate(90deg);
  border-bottom: solid 2px;
  height: 20px;
  color: #fff;
  font-weight: bolder;
  background-color: rgb(50, 61, 85);
}

.lineCenter {
  width: 100%;
  height: 2px;
  position: absolute;
  background-color: rgb(255, 255, 255);
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);
let sections = gsap.utils.toArray(".panel");
let numOfPanels = sections.length;
let lengthPanel = document.querySelector(".panel").offsetWidth;
if (window.innerWidth > 800) {
  lengthPanel = window.innerWidth;
}
let lengthAllPanels = lengthPanel * numOfPanels;

let scrollTween = gsap.to(sections, {
  scrollTrigger: {
    trigger: ".panelContainer",
    start: "bottom bottom",
    end: lengthAllPanels - lengthPanel,
    pin: true,
    scrub: true,
    snap: directionalSnap(1 / (numOfPanels - 1)),
  },
  x: -lengthAllPanels + lengthPanel,
  ease: "none",
});
function directionalSnap(increment) {
  let snapFunc = gsap.utils.snap(increment);
  return (raw, self) => {
    let n = snapFunc(raw);
    return Math.abs(n - raw) < 1e-4 || n < raw === self.direction < 0
      ? n
      : self.direction < 0
      ? n - increment
      : n + increment;
  };
}

idLinesTimeLine = [
  "2012",
  "2013",
  "2014",
  "2015",
  "2016",
  "2017",
  "2018",
  "2019",
  "2020",
  "2021",
];

idLinesTimeLine.forEach((year, i) => {
  gsap.to(`#id${year}`, {
    scrollTrigger: {
      trigger: `#pnl${year}`,
      containerAnimation: scrollTween,
      start: "center 55%",
      end: "center 45%",
      toggleActions: "play reset restart reset",
    },
    color: "yellow",
  });
});

//! ======CLICK BUG==========
let id2012 = document.getElementById("id2012");
let id2013 = document.getElementById("id2013");
let id2014 = document.getElementById("id2014");
let id2015 = document.getElementById("id2015");
let id2016 = document.getElementById("id2016");
let id2017 = document.getElementById("id2017");
let id2018 = document.getElementById("id2018");
let id2019 = document.getElementById("id2019");
let id2020 = document.getElementById("id2020");
let id2021 = document.getElementById("id2021");

id2012.addEventListener("click", () => goTo(0));
id2013.addEventListener("click", () => goTo(1));
id2014.addEventListener("click", () => goTo(2));
id2015.addEventListener("click", () => goTo(3));
id2016.addEventListener("click", () => goTo(4));
id2017.addEventListener("click", () => goTo(5));
id2018.addEventListener("click", () => goTo(6));
id2019.addEventListener("click", () => goTo(7));
id2020.addEventListener("click", () => goTo(8));
id2021.addEventListener("click", () => goTo(9));

function goTo(index) {
  console.log("goTo", index);
  let start = scrollTween.scrollTrigger.start,
      end = scrollTween.scrollTrigger.end,
      progress = index / (sections.length - 1);
  gsap.to(window, {
    scrollTo: start + (end - start) * progress
  });
}
              
            
!
999px

Console