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 id="scrollDist"></div>
<div id="container">

  <svg id="route" viewBox="0 50 3000 600" >
    
    <g id="tree">
      <path class="tree" d="M 50 100 C 20 80 10 40 60 30 C 120 40 140 100 50 100 L 50 180"/>
    </g>
    
    <use transform="translate(600,50)  scale(0.8)" href="#tree" />
     <use transform="translate(1200,25)  scale(0.8)" href="#tree" />
     <use id="tree04" transform="translate(2000,-50)  scale(1.1)" href="#tree" />
     <use id="tree05" transform="translate(2200,0)  scale(1)" href="#tree" />
     <use transform="translate(3010,100)  scale(0.8)" href="#tree" />
    
    <g id="guy" transform="translate(-16.908 101.924) scale(.15)">
      <path d="M345.038 160c-10.853 56.475 63.919 51.44 64.962 4.955" fill="#ebebeb" stroke="#000" stroke-width="13.33"/>

      <g class="rad">
        <circle cx="260" cy="426" r="75" fill="none" stroke="black" stroke-width="10"/>
        <circle cx="260" cy="426" r="10" fill="none" stroke="black" stroke-width="5"/>
 
        <path d="M 250 422 L 185 400" stroke="black" stroke-width="3"/>
      </g>
      <g class="rad">
        <circle cx="500" cy="426" r="75" fill="none" stroke="black" stroke-width="10"/>
        <circle cx="500" cy="426" r="10" fill="none" stroke="black" stroke-width="5"/>
        <path d="M 490 420 L 430 400" stroke="black" stroke-width="3"/>
      </g>

      <path d="M270 425h110l67-115H310l-50 105" fill="none" stroke="#000" stroke-width="13.33" stroke-linecap="butt"/>
      <path d="M440 290l55 123" fill="none" stroke="#000" stroke-width="13.33" stroke-linecap="butt"/>
      <path d="M320 210c28.865-15.119 43.916-12.855 50 10 5.308 19.94 21.148 35.799 40 45 4.328 2.112 19.495 8.956 30 10 7.348 11.768 9.233 24.578-10 15-27.597-1.495-55.713-23.294-70-50l-30 60c14.819 14.311 31.427 27.676 50 40 2.199 1.891 14.145 9.426 10 30l-5 55 15 5c10.114 3.649 12.603 9.521 0 10h-40c7.21-27.894 11.5-54.439 5-80-14.994-24.682-91.176-12.316-95-50-3.835-37.791 10.071-70.107 50-100z" fill="#ebebeb" stroke="#000" stroke-width="13.33"/>
      <path d="M440 160c-17.141-24.638-37.736-39.381-80-40-40.544-.594-51.028 20.679-20 40h100z" fill="green" stroke="#000" stroke-width="8" transform="matrix(.93186 0 0 .9997 19.981 .049)"/>
      <path d="M370 160l5.317 40" fill="none" stroke="#000" stroke-width="13.33"/>
      <path d="M270 280l60 20" fill="none" stroke="#000" stroke-width="13.33" stroke-linecap="butt"/>
    </g>
    <path id="path" d="M -300 180 L 0 180 c 60 0 180 -20 280 0 40 10 130 11.853 200 0 135 -23 240 -5 340 20 235 50 330 -32 460 -40 110 -8 310 30 330 30 120 20 290 15 350 -30 55 -40 210 -10 300 20 50 15 180 15 260 0 120 -20 180 -30 240 20 40 30 85 25 120 25 40 -0 140 -0 180 0 " fill="none" stroke="none" />
    <path  d="M -350 180 L 0 180 c 60 0 180 -20 280 0 40 10 130 11.853 200 0 135 -23 240 -5 340 20 235 50 330 -32 460 -40 110 -8 310 30 330 30 120 20 290 15 350 -30 55 -40 210 -10 300 20 50 15 180 15 260 0 120 -20 180 -30 240 20 40 30 85 25 120 25 40 -0 140 -0 180 0 L 3000 600 L -350 600" fill="green" stroke="none" />

    <path  d="M 3000 225 L 4000 225 L 4000 600 L 3000 600" fill="green" stroke="none" />
  </svg>

</div>
              
            
!

CSS

              
                body{
  margin:0;
  background-color:#72c1e0;
}
#container{
  visibility:hidden;
  margin-top:30vh;
}

#route{
  position:absolute;
  width: 500vw;
  overflow: visible;
}
.tree{
  fill: green;
  stroke: #1c5a1c;
  stroke-width: 6;
}
              
            
!

JS

              
                console.clear();

// set initial states


gsap.set("#guy", { scaleX: 0.15});

var wh = window.innerHeight,
    speed = 20,
    scrollDist = wh * speed,
    scrollEnd = wh * (speed - 1),
    route = document.getElementById('route'),
    routeWidth = route.getBoundingClientRect().width;
console.log(routeWidth);

gsap.set('#scrollDist', {width:'100%', height:scrollDist})
gsap.set('#container', {position:'fixed', width:routeWidth, left:200, top:0,  autoAlpha:1})


//tween the svg path + cyclist + wheels 
gsap.timeline({
  defaults:{duration:1, ease:'none'}, 
  scrollTrigger:{
    trigger:'#scrollDist', 
    start:'top top', 
    end:'+=' + scrollEnd, 
    scrub:0.3,
    onUpdate: (self) => {
      gsap.set('#container', {x:-routeWidth*(self.progress)});
      
      gsap.set('.rad', {
        rotation:() => self.direction === 1 ? 360*30*(self.progress) :  -360*30*(self.progress), 
        transformOrigin:'center',
        overwrite: 'auto'})
      
      gsap.to("#guy", { scaleX: () => self.direction === 1 ? 0.15 : -0.15, overwrite: 'auto', duration: 0.2});
      
      console.log(self.progress) //  info for position
    },

  }
}) 
  .to('#guy', {
  motionPath:{
    path: "#path",
    align: "#path",
    alignOrigin: [0.5, 1],
    autoRotate: true,
    start:0.1
  }
})
.to('#tree04', {rotation:20, transformOrigin:'center bottom', duration: 0.01, repeat:1, yoyo:true}, 0.665)
.to('#tree05', {rotation:-20, transformOrigin:'center bottom', duration: 0.01, repeat:1, yoyo:true}, 0.665)

window.onresize = ()=> { 
  gsap.set('#container', {left:200});
  routeWidth = route.getBoundingClientRect().width;
  ScrollTrigger.refresh()
}

              
            
!
999px

Console