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

              
                <div class="home">
  <div class="container">
    <div class="wrapper">
      <p>This is a fairly short sentence.</p>
    </div>
  </div>

  <div class="container">
    <div class="wrapper">
      <p>This is a much longer short sentence to illustrate that they are moving at the same "rate".</p>
    </div>
  </div>
</div>
              
            
!

CSS

              
                .home {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.container{
  white-space: nowrap;
  margin: 1em;
  overflow: hidden;
  background: #CCC;
}
.container p{
  margin: 0;
  padding: 0;
  display: inline-block;
  font-size: 4vw;
  font-family: arial;
}
              
            
!

JS

              
                // Rate = Distance over Time r=d/t
// If we want to define the rate, and 
// the distance is determined, 
// time will have to be variable

// We want to define the rate, and we can 
// define that statically
r = 100;
adjustJank = 4; // Set this to 0 to see the jank I'm talking about ... this just adds to the distance animated to smooth out the seam

// Get the initial scroll elements and save them for later
const scrollElems = document.querySelectorAll('.container p');

// Adjust our tween based on the object and distance given
function adjustTween(obj, d) {
  // Get the progress of the previous tween if it exists
  let progress = 0;
  if(obj.tween) {
    progress = obj.tween.progress();
    // Kill the previous tween
    obj.tween.kill();
  }
    
  // r = d/t 
  // r*t = d
  // t = d/r
  
  // Set the proper time
  var t = d/r;

  // Create a new tween to animate our text so that it loops
  // Make sure to save it to the object so we can refer to it later
  obj.tween = gsap.fromTo(obj.parentElement, {x: 0}, {
    duration: t,
    x: "-"+(d+adjustJank), 
    ease: 'linear',
    repeat: -1,
  }).progress(progress); // Set the progress of the new tween to the same value of
                         // the previous tween (if it exists) before it was killed
}

// Set up for what appears to be an seamless stream of text
// This could go in an init() function
scrollElems.forEach((obj, i) => {
  var d = obj.offsetWidth;
  var parent = obj.parentElement;
  var clone = obj.cloneNode(true);
  parent.appendChild(clone);
  gsap.set(parent.parentElement, {width: d});
  
  adjustTween(obj, d);
});

// Adjust widths and tweens on resize
window.addEventListener("resize", () => {
  scrollElems.forEach((obj, i) => {
    var d = obj.offsetWidth;
    var parent = obj.parentElement;
    gsap.set(parent.parentElement, {width: d});
    adjustTween(obj, d);
  });
});
              
            
!
999px

Console