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 id="wrap">
  
  <div class="ball-container">
    <div class="ball"></div>
  </div>
  
  <svg id="movingSVG" viewbox="0 0 300 800">

    <path id="motionP" d="M 300 20 C 160 0 10 50 30 120 Q 90 340 140 240 C 240 60 290 220 130 480 C 40 650 290 540 150 670 L 300 830"/>

    <rect id="point" x="270" y="-5" width="30" height="30" fill="beige" />
    
  </svg>
  
  
  

</div>

<div id="check"></div>
              
            
!

CSS

              
                body{
  margin:0;
  background-color: grey;
  height:1200vh;
  background-image: linear-gradient( #0000002b .1em, transparent .1em);
  background-size: 25vh 25vh;
}
#check{
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
/*   height: calc(50vh + 10px); */
  height: 50vh;
  border-bottom: 1px solid red;
}
#wrap{
  position: absolute;
  top: 50vh;
  right: 0;
  
}
#movingSVG{
  position: absolute;
  top: 0;
  right: -35px;
  height: 800px;
  overflow: visible;
  
  outline: 1px solid orange;
}
#motionP{
  fill: none;
  stroke: green;
  stroke-width: 20;
}

.ball {
  width: 100px;
  height: 100px;
  background: red;
  border-radius: 50%;
}

.ball-container {
  position: absolute;
  top: 0;
  right: -35px;
  height: 800px;
  overflow: visible;
  outline: 1px solid blue;
}
              
            
!

JS

              
                console.clear();

let setBallY = gsap.quickSetter(".ball-container", "y", "px");
let props = gsap.getProperty(".ball");

gsap.timeline({
  defaults:{ ease: 'none' }, 
  scrollTrigger:{
    trigger:'#wrap', 
    pin: true,
    start:'top 50%', 
    end: '+=3000' ,  // value for 'speed'
    scrub: true, // important !
    pinSpacing: false,
    onUpdate: ({progress}) => {

      // move the SVG so that the moving 'point' 
      // remains at the same level of viewport'.

      const ySet = gsap.quickSetter('#movingSVG', "y", "px");
      let posY = gsap.getProperty('#point', 'y');      
      ySet(-posY);
      
      // -50 for the half the height
      setBallY(-props("y") - 50);

      // info for position = progress
      console.log(progress)
    }
  }
})
.to('#point', {
  motionPath:{
    path: "#motionP",
    align: "#motionP",
    alignOrigin: [ 0.5, 0.5 ],
    end: 0.5
  },
  duration: 0.5
})
// .to('#point', {fill: 'red', scale: 1.5, duration:0.04}, '+=0.2')

.to('#point', {
  motionPath:{
    path: "#motionP",
    align: "#motionP",
    alignOrigin: [ 0.5, 0.5 ],
    start: 0.5,
    end: 1
  },
  duration: 0.5
})

 .to(".ball", {
  motionPath:{
    path: "#motionP",
    align: "#motionP",
    alignOrigin: [ 0.5, 0.5 ],
    end: 0.5
  },
  duration: 0.5
}, 0)
.to(".ball", {
  motionPath:{
    path: "#motionP",
    align: "#motionP",
    alignOrigin: [ 0.5, 0.5 ],
    start: 0.5,
    end: 1
  },
  duration: 0.5
}, 0.5)
              
            
!
999px

Console