Pen Settings



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


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


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.


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.


                <div class='scrollContainer'>
    <div class='section'>ScrollTrigger with Draggable</div>
    <div class='section'></div>
    <div class='section'></div>
    <div class='section'></div>
<div class="proxy"></div>


                body {
  margin: 0;
  padding: 0;
  overflow: hidden;

.scrollContainer {
  width: 600%;
  display: flex;
  flex-wrap: nowrap;

.section {
  height: 100vh;
  width: 100vw;
  text-align: center;
  font-size: 36px;
  line-height: 90vh;

.section:nth-child(1) {
  background-color: #deb887;

.section:nth-child(2) {
  background-color: limegreen;

.section:nth-child(3) {
  background-color: #b8860b;

.section:nth-child(4) {
  background-color: #2f4f4f;

.proxy {
  position: absolute;
  visibility: hidden;


                let sections = document.querySelectorAll(".section");
let scrollContainer = document.querySelector(".scrollContainer");
let clamp, dragRatio;

let scrollTween =, {
  xPercent: -100 * (sections.length - 1),
  ease: "none"

let horizontalScroll = ScrollTrigger.create({
  animation: scrollTween,
  trigger: scrollContainer,
  pin: true,
  scrub: 1,
  end: () => "+=" + scrollContainer.offsetWidth,

var drag = Draggable.create(".proxy", {
  trigger: scrollContainer,
  type: "x",
  onPress() {
    clamp || ScrollTrigger.refresh();
    this.startScroll = horizontalScroll.scroll();
  onDrag() {
    horizontalScroll.scroll(clamp(this.startScroll - (this.x - this.startX) * dragRatio));
    // if you don't want it to lag at all while dragging (due to the 1-second scrub), uncomment the next line:

ScrollTrigger.addEventListener("refresh", () => {
  clamp = gsap.utils.clamp(horizontalScroll.start + 1, horizontalScroll.end - 1); // don't let the drag-scroll hit the very start or end so that it doesn't unpin
  // total scroll amount divided by the total distance that the sections move gives us the ratio we can apply to the pointer movement so that it fits. 
  dragRatio = scrollContainer.offsetWidth / (window.innerWidth * (sections.length - 1));