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="canvas-container">
    <div class="container1">
      <div class="content-container">
        <div class="imgtop"></div>
        <div class="imgbottom"></div>
      </div>
      <div class="imgcontent1"></div>
    </div>
</div>
              
            
!

CSS

              
                .canvas-container {
  height: 200vh;
}
.container1 {
  width:400px; 
  height:600px;
  margin: 0 auto;
}
.content-container {
  position: relative;
  z-index: 9;
}
.imgtop {
  width:400px; 
  height:100px;
  background: #0cc;
}
.imgbottom {
  width:400px; 
  height:500px;
  background: #005;
}
.imgcontent1 {
  position: absolute;
  top:0;
  left:0;
  width:400px; 
  height:600px;
  background:#c00;
}
              
            
!

JS

              
                	// Initialize ScrollTrigger
gsap.registerPlugin(ScrollTrigger);
var speed = 0.1;
var wheelTimeline = gsap.timeline({
  paused: true,
  onUpdate: function() {
    this.time(this.time() * speed);
  }
});
// Create a timeline for the rotation of #my-element
var rotateTimeline = gsap.timeline({
  scrollTrigger: {
    trigger: ".container1", // ID of the element to animate
    start: "center center", // Animation starts when the top of the element reaches the center of the viewport
    end: "bottom center", // Animation ends when the bottom of the element reaches the center of the viewport
    scrub: true, // Animation is scrubbed (played back and forth) during scrolling
    markers: false, // Add markers to visualize the trigger and end points of the animation
	pin: true // Pin the element in the viewport for the duration of the animation
  }
});
rotateTimeline.to(".container1", {rotation: "90deg", ease: "none"});

// Create a timeline for the animation of imgtop
var imgTopTimeline = gsap.timeline({
  scrollTrigger: {
    trigger: ".container1", // ID of the element to animate
    start: "top center", // Animation starts when the top of the element reaches the center of the viewport
    end: "bottom center", // Animation ends when the bottom of the element reaches the center of the viewport
    scrub: true, // Animation is scrubbed (played back and forth) during scrolling
    markers: false, // Add markers to visualize the trigger and end points of the animation

  }
});
imgTopTimeline.to(".imgtop", {y: "-800px", ease: "power1.inOut", delay: 800, duration: 200});

// Create a timeline for the animation of imgbottom
var imgBottomTimeline = gsap.timeline({
  scrollTrigger: {
    trigger: ".container1", // ID of the element to animate
    start: "top center", // Animation starts when the top of the element reaches the center of the viewport
    end: "bottom center", // Animation ends when the bottom of the element reaches the center of the viewport
    scrub: true, // Animation is scrubbed (played back and forth) during scrolling
    markers: false, // Add markers to visualize the trigger and end points of the animation

  }
});
imgBottomTimeline.to(".imgbottom", {y: "800px", ease: "slow", delay: 1000, duration: 200});

// Create a timeline for the animation of imgcontent1
var imgContent1Timeline = gsap.timeline({
  scrollTrigger: {
    trigger: ".container1", // ID of the element to animate
    start: "top center", // Animation starts when the top of the element reaches the center of the viewport
    end: "bottom center", // Animation ends when the bottom of the element reaches the center of the viewport
    scrub: true, // Animation is scrubbed (played back and forth) during scrolling
    markers: false, // Add markers to visualize the trigger and end points of the animation

  }
});
imgContent1Timeline.to(".imgcontent1", {y: "-200px", ease: "slow", delay: 1000, duration: 50});

// Control the animation speed based on mouse wheel scrolling

$(document).on("wheel", function(event) {
  event.preventDefault();
  speed += event.originalEvent.deltaY * -0.001;
  speed = Math.max(0.1, Math.min(5, speed)); // Limita la velocità tra 0.1 e 5
  wheelTimeline.invalidate().play();
});
              
            
!
999px

Console