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="container">
  <div class="bar">
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
  </div>
  <div class="amount">$0.00</div>
</div>
              
            
!

CSS

              
                body {
  text-align: center;
  min-height: 400vh;
}

.bar {
  width: 80vw;
  height: 30vh;
  border: 4px solid gray;
  margin: auto;
  padding: 8px;
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.amount {
  margin: 20px;
  font-size: 36px;
}

.box {
  background-color: #c0a711;
  flex-grow: 1;
}
              
            
!

JS

              
                let tl = gsap.timeline({
  scrollTrigger: {
    trigger: ".container",
    start: "top 8px",
    end: "top 8px",
//    end: "+=800", // pin for 800 pixels worth of scroll
    scrub: false,
    //pin: true
  }
});

tl.from(".box", {
  visibility: "hidden",
  duration: 0.01, // just a tiny amount of duration so it's like a toggle since visibility isn't really animatable. 
  stagger: 0.1 // stagger the starting time of each subsequent reveal
}).tweenTo(tl.duration() * 0.75);

// create a proxy object so we can tween the numeric value and plug it into the amount element's innerText using an onUpdate()
let amountProxy = {value: 0},
    amountEl = document.querySelector(".amount");
tl.to(amountProxy, {
  value: 800,
  onUpdate: () => amountEl.innerText = "$" + formatNumber(amountProxy.value, 2),
  duration: tl.duration(), // just match however long the entire timeline is at this point (it's only populated with the visibility toggles, so it'll stretch to fit those exactly)
  ease: "none"
}, 0) // <- position parameter places it at the very start of the timeline, so it overlaps with the toggling visibility stuff.


// a helper function for formatting a number - it adds commas and forces a certain number of decimal places.
function formatNumber(value, decimals) {
  let s = (+value).toLocaleString('en-US').split(".");
  return decimals ? s[0] + "." + ((s[1] || "") + "00000000").substr(0, decimals) : s[0];
}
              
            
!
999px

Console