Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                             <div class="hero-marquee">
 <div class="marquee__inner">
                <div class="marquee__wrapper">
                  <div class="box typography-headline-hero text-uppercase fw-bold">Live, Breathe</div>
             
                </div>
              </div>
                </div>

<script src="https://unpkg.com/gsap@latest/dist/gsap.min.js"></script> 
              
            
!

CSS

              
                body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.hero-marquee {
  overflow: hidden;
  white-space: nowrap;
}
.box {
  width: 500vh;
  color: #000;
}
.typography-headline-hero {
	font-size: 15vw;
	font-family: roboto
}
.hero-marquee {
  overflow: hidden;
  white-space: nowrap;
  max-width: 1140px;
  margin: auto;
}
.marquee__wrapper {
  display: flex;
  font-size: 0;
}

              
            
!

JS

              
                // JavaScript Document
let marquee = document.querySelectorAll(".marquee__wrapper");

// added event listener because it doesn't get the right width
addEventListener("load", function () {
  marquee.forEach((wrapper, index) => {
    let el = wrapper.querySelector(".box");
    // set a default rate, the higher the value, the faster it is

    let rate = 230;
    if (index === 1) {
      rate = 200;
    } else if (index === 2) {
      rate = 150;
    }
    // get the width of the element
    let distance = el.getBoundingClientRect().width;
    // get the margin-right of the element
    let style = window.getComputedStyle(el);
    let marginRight = parseInt(style.marginRight, 10) || 0;

    // get the total width of the element
    let totalDistance = parseFloat(distance.toFixed(2), 10);
    // get the duration of the animation
    let time = totalDistance / rate;
    console.log(totalDistance, "totalDistance");
    // get the parent of the element
    let container = el.parentElement;

    gsap.set(".typography-headline-hero", {
  xPercent: 100,
});	  
    
    gsap.to(container, {
      repeat: -1,
      x: -1 * totalDistance,
      ease: "none",
      duration: 30,
      paused: false
    });
gsap.to(".typography-headline-hero", {
  xPercent: -100,
  duration: 6,
  delay: 0.2,
  ease: "none"
});	  
  });
});
              
            
!
999px

Console