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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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="container">
  <div id="section1" class="description panel blue">
    <div><h1>Horizontal snapping sections (simple)</h1>
      <p>Scroll vertically to scrub the horizontal animation. It also dynamically snaps to the sections in an organic way based on the velocity. The snapping occurs based on the natural ending position after momentum is applied, not a simplistic "wherever it is when the user stops".</p>

  </div>


  <section id="section2" class="panel red">
    ONE
    <p id="text-1" style="position:absolute; top: 3em;">Text example 1 Section 1 </p>
    <p id="text-2"style="position:absolute; top: 9em;">Text example 2 test example section 1</p>
  </section>
    
    
  <section id="section3" class="panel orange">
    TWO
    <p id="text-3" style="position:absolute; top: 3em;">Text example 1 Section 2 </p>
    <p id="text-4"style="position:absolute; top: 9em;">Text example 2 test example section 1</p>
  </section>
  <section class="panel purple">
    THREE


  </section>
  <section class="panel green">
    FOUR
  </section>
  <section class="panel gray">
    FIVE
  </section>

</div>



<header>
  <a href="https://greensock.com/scrolltrigger">
    <img class="greensock-icon" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/scroll-trigger-logo-light.svg" width="200" height="64" />
  </a> 
</header>
              
            
!

CSS

              
                .container {
  width: 600%;
  height: 100%;
  display: flex;
  flex-wrap: nowrap;
}

              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger);

  var section1Width = 0;
  var section1Start = 0;
  var section1End = 0;
  var section1Length = 0;
  //Variabili sezione 2
  var section2Width = 0;
  var section2Start = 0;
  var section2End = 0;
  var section2Length = 0;

  //Variabili sezione 3
  var section3Width = 0;
  var section3Start = 0;
  var section3End = 0;

let sections = gsap.utils.toArray(".panel");

 let maxWidth = 0;
    console.log(sections);
    let index = 0;
    const getaMaxWidth = () => {
      maxWidth = 0;
      sections.forEach((section) => {
        index++;
        switch (index) {
          case 1:
            console.log(section);
            section1Width = section.offsetWidth;
            section1Length = section.offsetHeight;
            break;
          case 2:
            section2Width = section.offsetWidth;
            section2Length = section.offsetHeight;

            break;
          case 3:
            section3Width = section.offsetWidth;
            break;
        }
                maxWidth += section.offsetWidth;
        maxLength += section.offsetLength;
      });


}
              
            
!
999px

Console