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="wrapper d-flex flex-nowrap">
	
	<section class="section section--large flex-shrink-0 d-flex line-right">text</section>
	  
	<section class="section section--small flex-shrink-0 d-flex line-right">text</section>
	
	<section class="section section--small flex-shrink-0 d-flex line-right">text</section>
	  
	<section class="section section--large flex-shrink-0 d-flex">text</section>
	  
</div>

<div class="drag-proxy"></div>
              
            
!

CSS

              
                * {
  margin:0;
}

body {
	overflow-x: hidden;
}
	
.section--large {
  height:100vh;
  width: 100vw;
  background-color: #ffd103;
}

.section--small {
  height:100vh;
  background-color: #ffd103;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 400px;
  width: 40vw;
  max-width: 600px;
  overflow:hidden;
  margin: 0 auto;
  position: relative;
}

.line-right {
	border-right:1px solid #000000;
}

.drag-proxy {
	  visibility: hidden;
	  position: absolute;
	}

html, body {
  scroll-behavior: auto !important;
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger, Draggable);

const sections = gsap.utils.toArray("section");
let maxWidth = 0;

const getMaxWidth = () => {
  maxWidth = 0;
  sections.forEach((section) => {
	maxWidth += section.offsetWidth;
  });
};
getMaxWidth();
ScrollTrigger.addEventListener("refreshInit", getMaxWidth);

let scrollTween = gsap.to(sections, {
  x: () => `-${maxWidth - window.innerWidth}`,
  ease: "none",
});

let horizontalScroll = ScrollTrigger.create({
  animation: scrollTween,
  trigger: ".wrapper",
	pin: true,
	scrub: true,
	end: () => `+=${maxWidth}`,
	invalidateOnRefresh: true
});



//sections.forEach((sct, i) => {
//  ScrollTrigger.create({
//	trigger: sct,
//	start: () => 'top top-=' + (sct.offsetLeft - window.innerWidth/2) * (maxWidth / (maxWidth - window.innerWidth)),
//	end: () => '+=' + sct.offsetWidth * (maxWidth / (maxWidth - window.innerWidth)),
//	toggleClass: {targets: sct, className: "active"}
//  });
//});




// dragRatio changed to the part in the horizontal sroll that's there to calculate the offset between the duration of the scroll and the amount of x-translation of the content (that needs to be included there when triggering things when certain sections reach a certain point in the viewport - as seen in commented out part above)

var dragRatio = (maxWidth / (maxWidth - window.innerWidth))

var drag = Draggable.create(".drag-proxy", {
  trigger: '.wrapper',
  type: "x",
  inertia: true,
  allowContextMenu: true,
  onPress() {
    this.startScroll = horizontalScroll.scroll();
  },
  onDrag() {
    horizontalScroll.scroll(this.startScroll - (this.x - this.startX) * dragRatio);
  },
  onThrowUpdate() {
    horizontalScroll.scroll(this.startScroll - (this.x - this.startX) * dragRatio);
  }
})[0];
              
            
!
999px

Console