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="preload">
  <p>Let's cycling - DRAG</p>
</div>
<div class="container-bike">
  <div class="background">

    <div class="tree">
      <div class="tree-img"></div>
    </div>
    <div class="tree">
      <div class="tree-img"></div>
    </div>
    <div class="tree">
      <div class="tree-img"></div>
    </div>
    <div class="tree">
      <div class="tree-img"></div>
    </div>
    <div class="tree">
      <div class="tree-img"></div>
    </div>

    <div class="tree">
      <div class="tree-img"></div>
    </div>
    <div class="tree">
      <div class="tree-img"></div>
    </div>
    <div class="tree">
      <div class="tree-img"></div>
    </div>

  </div>
  <div class="bike">

    <div class="cyclist">
      <div class="body">
        <div class="body-box"></div>
        <div class="body-arm"></div>
      </div>
      <div class="legs-right">
        <div class="legs-part"></div>
      </div>
      <div class="legs-left">
        <div class="legs-part"></div>
      </div>
    </div>

    <div class="frame">
      <div class="frame-1"></div>
      <div class="frame-2"></div>
      <div class="frame-3"></div>
    </div>
    <div class="wheel-particle">
      <div></div>
      <div></div>
      <div></div>
    </div>
    <div class="wheel">
      <div class="wheel-radial"></div>
    </div>
    <div class="wheel">
      <div class="wheel-radial"></div>
    </div>

  </div>
  <div class="floor"></div>
</div>
              
            
!

CSS

              
                .preload {
  background-color: #1F317F;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  p {
    color: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 18px;
    font-family: Helvetica;
    letter-spacing: 2px;
  }
}

.container-bike {
  cursor: move;
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  .background {
    display: flex;
    justify-content: space-around;
    will-change: transform;
    left: -50%;
    height: 50%;
    width: 300%;
    .tree {
      position: relative;
      height: 100%;
      width: 180px;
      &-img {
        background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyMTkuMDMzIDM0Ny41MTIiPjxwYXRoIGZpbGw9IiM2NTZDNDgiIGQ9Ik00My41NCAxNDIuMzR2LTEuMDdjLTEuNiA1LjM0LTIuNDUgMTEtMi40NSAxNi44OCAwIDMyLjQ0IDI2LjMgNTguNzUgNTguNzQgNTguNzUgNi45NCAwIDEzLjYtMS4yIDE5Ljc3LTMuNDItMS41Ny4xLTMuMTUuMTctNC43NS4xNy0zOS4zOCAwLTcxLjMtMzEuOTMtNzEuMy03MS4zeiIvPjxwYXRoIGZpbGw9IiM3QjgyNTAiIGQ9Ik0xNTguNiAxNTguMTVjMC0zMi40NS0yNi4zLTU4Ljc2LTU4Ljc2LTU4Ljc2LTI2LjU4IDAtNDkuMDMgMTcuNjUtNTYuMjggNDEuODdsLS4wMiAxLjA3YzAgMzkuMzggMzEuOTMgNzEuMyA3MS4zIDcxLjMgMS42IDAgMy4yLS4wNSA0Ljc3LS4xNiAyMi43My04LjEgMzktMjkuODIgMzktNTUuMzN6Ii8+PHBhdGggZmlsbD0iIzYwNTY1NyIgZD0iTTEyMy44MyAxNjAuMWwtLjYzLTIyLjk4LTYuMyAxLjk0LTEuMTQg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;
        bottom: -40px;
        width: 150px;
        height: 380px;
        background-repeat: no-repeat;
        background-position: 0 100%;
      }
    }
  }
  .floor {
    background-color: #9DCB84;
    will-change: transform;
    position: absolute;
    top: 50%;
    left: -100%;
    height: 200%;
    width: 400%;
  }
  .bike {
    position: absolute;
    top: calc(50% - 100px);
    left: 50%;
    margin-left: -75px;
    will-change: transform;
    height: 100px;
    width: 120px;
    .cyclist {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      .body {
        background-color: #000;
        position: absolute;
        top: 26px;
        left: 45px;
        width: 11px;
        height: 15px;
        transform-origin: top left;
        transform: rotate(-45deg);
        z-index: 4;
        &::after {
          background-color: #000;
          content: "";
          position: absolute;
          top: 2px;
          left: 14px;
          width: 100%;
          height: 100%;
          transform: rotate(25deg);
          transform-origin: top;
        }
        &-box {
          background-color: #ffcc99;
          position: absolute;
          top: 0px;
          left: 25px;
          width: 11px;
          height: 15px;
          &::after {
            background-color: #F76363;
            content: "";
            position: absolute;
            top: -1px;
            right: -2px;
            width: 55%;
            height: 19px;
          }
        }
        &-arm {
          background-color: #000;
          position: absolute;
          top: 8px;
          left: 13px;
          width: 7px;
          height: 15px;
          transform-origin: top left;
          transform: rotate(5deg);
          z-index: 3;
          &::after {
            background-color: #ffcc99;
            content: "";
            position: absolute;
            top: 16px;
            left: 0px;
            width: 80%;
            height: 100%;
            -webkit-transform: rotate(25deg);
            transform: rotate(-18deg);
            -webkit-transform-origin: top;
            transform-origin: top;
          }
        }
      }
      .legs-right,
      .legs-left {
        background-color: #000;
        position: absolute;
        top: 35px;
        left: 40px;
        width: 12px;
        height: 33px;
        transform-origin: top left;
        .legs-part {
          background-color: rgba(255, 204, 153, 1);
          position: absolute;
          top: 32px;
          left: 0;
          width: 8px;
          height: 28px;
          transform: rotate(65deg);
          transform-origin: top center;
          &::after {
            background-color: #F76363;
            content: "";
            position: absolute;
            bottom: 0px;
            right: -5px;
            width: 14px;
            height: 5px;
          }
        }
      }
      .legs-right {
        transform: rotate(-30deg);
        z-index: 3;
      }
      .legs-left {
        transform: rotate(-63deg);
      }
    }
    .frame {
      position: absolute;
      bottom: 23px;
      left: 22px;
      height: 40px;
      width: 76px;
      z-index: 2;
      .frame-1,
      .frame-2 {
        background-color: #fff;
        transform-origin: bottom center;
        position: absolute;
        height: 40px;
        width: 3px;
        &::after,
        &::before {
          background-color: #fff;
          content: "";
          position: absolute;
        }
      }
      .frame-1 {
        left: 36px;
        transform: rotate(-20deg);
        &::after {
          width: 2px;
          height: 35px;
          bottom: 0;
          left: 0;
          transform: rotate(-70deg);
          transform-origin: bottom;
        }
        &::before {
          width: 2px;
          height: 37px;
          top: 12px;
          left: 0;
          transform: rotate(65deg);
          transform-origin: top;
        }
      }
      .frame-2 {
        right: 0;
        transform: rotate(-30deg);
        &::after {
          width: 2px;
          height: 32px;
          top: 9px;
          left: 0;
          transform: rotate(117deg);
          transform-origin: top;
        }
        &::before {
          width: 2px;
          height: 35px;
          top: 8px;
          left: 0;
          transform: rotate(65deg);
          transform-origin: top;
        }
      }
      .frame-3 {
        position: absolute;
        top: -2px;
        left: 20px;
        height: 40px;
        width: 48px;
        &::after,
        &::before {
          background-color: #000;
          border-radius: 4px;
          content: "";
          position: absolute;
          width: 4px;
        }
        &::after {
          height: 12px;
          top: 7px;
          right: 13px;
          transform: rotate(-90deg);
          transform-origin: top;
        }
        &::before {
          height: 15px;
          top: 3px;
          left: -4px;
          transform: rotate(-90deg);
          transform-origin: top;
        }
      }
    }
    .wheel {
      border: 6px solid black;
      border-radius: 50%;
      position: absolute;
      bottom: 0;
      height: 45px;
      width: 45px;
      &:first-child {
        left: 0;
      }
      &:last-child {
        right: 0;
      }
      &::after,
      &::before {
        background-color: #fff;
        content: "";
        position: absolute;
        height: 100%;
        width: 1px;
      }
      &::after {
        top: 0;
        left: 50%;
        transform: translateX(-50%);
      }
      &::before {
        top: 50%;
        left: 50%;
        transform: translateY(-50%) translateX(-50%) rotate(90deg);
      }
      &-particle {
        position: absolute;
        bottom: 0px;
        left: -25px;
        height: 20px;
        width: 30px;
        div {
          background-color: #313E35;
          border-radius: 50%;
          position: absolute;
          bottom: 0;
          right: 0;
          height: 8px;
          width: 8px;
          opacity: 0;
        }
      }
      &-radial {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 100%;
        transform: rotate(45deg);
        &::after,
        &::before {
          background-color: #fff;
          content: "";
          position: absolute;
          height: 100%;
          width: 1px;
        }
        &::after {
          top: 0;
          left: 50%;
          transform: translateX(-50%);
        }
        &::before {
          top: 50%;
          left: 50%;
          transform: translateY(-50%) translateX(-50%) rotate(90deg);
        }
      }
    }
  }
}

* {
  margin: 0;
  padding: 0;
}

*,
*:after,
*:before {
  box-sizing: border-box;
}

body {
  background: rgb(160, 213, 255);
  overflow: hidden;
}

body,
html {
  height: 100%;
  width: 100%;
}
              
            
!

JS

              
                 /*

 author: Marco Barría
 devDependencies:
   - GSAP TweenMax https://greensock.com/tweenmax (Necessary for animation.)
   - GSAP Draggable
   - NO jQuery

 */

 var _preload = document.querySelector('.preload'),
   _world = document.querySelector('.container-bike'),
   _back = document.querySelector('.background'),
   _tree = document.querySelectorAll('.tree'),
   _bike = document.querySelector('.bike'),
   _headerCyclo = document.querySelector('.body-box'),
   _legsRight = document.querySelector('.legs-right'),
   _legsLeft = document.querySelector('.legs-left'),
   _legsRightPart = document.querySelector('.legs-part'),
   _wheel = document.querySelectorAll('.wheel'),
   _wheelParticle = document.querySelectorAll('.wheel-particle > div');

 TweenMax.set([_wheel, _world], {
   transformOrigin: '50% 50%'
 });

 TweenMax.set(_tree, {
   transformOrigin: '50% 100%'
 });

 var initAnimation = function initAnimation() {

   function initText() {
     var tl = new TimelineMax();
     tl.to(_preload, 1, {
       alpha: 0,
       ease: Power2.easeOut,
       onComplete: function() {
         _preload.style.display = "none";
       }
     })
     return tl;
   }

   function initTree() {
     var tl = new TimelineMax();
     tl.staggerFromTo(_tree, 1, {
       opacity: 0,
       y: 400,
       force3D: true,
       scale: 0,
     }, {
       opacity: 1,
       y: 0,
       scale: 1,
       force3D: true,
       ease: Elastic.easeOut.config(0.9, 0.7)
     }, 0.2);
     return tl;
   }

   function initBike() {
     var tl = new TimelineMax();
     tl.fromTo(_bike, 1, {
       opacity: 0,
       x: -500,
       force3D: true,
       ease: Power2.easeIn
     }, {
       opacity: 1,
       x: 0,
       force3D: true,
       ease: Power2.easeOut
     })
     return tl;
   }

   var masterInit = new TimelineMax({
     onStart: function() {
       init();
     }
   });
   masterInit.add(initText(), "+=3", "scene1")
     .add(initTree(), "scene2")
     .add(initBike(), "-=1.5", "scene3");
   masterInit.timeScale(1);

 };

 var init = function init() {

   function cyclo(el, value1, value2) {
     var tl = new TimelineMax();
     tl.to(el, 1, {
         rotation: value1,
         force3D: true,
         ease: Power0.easeNone,
       })
       .to(el, 1, {
         rotation: value2,
         force3D: true,
         ease: Power0.easeNone
       });
     return tl;
   }

   function headerCyclo(r) {
     TweenMax.to(_headerCyclo, 0.5, {
       rotation: r,
       ease: Power2.easeOut
     })
   }

   function backgroundMove() {
     var tl = new TimelineMax();
     tl.to(_back, 8, {
       x: -50 + '%',
       force3D: true,
       ease: Power0.easeNone
     });
     return tl;
   }

   function rotateTree(n) {
     TweenMax.set(_tree, {
       rotation: n
     });
   }

   function leftRightBike(v) {
     TweenMax.to(_bike, 1, {
       x: v,
       ease: Power2.easeOut
     })
   }

   function rotateWheel() {
     var tl = new TimelineMax();
     tl.to(_wheel, 1, {
       rotation: 360,
       ease: Power0.easeNone
     });
     return tl;
   }

   function wheelParticle() {
     var tl = new TimelineMax();
     tl.staggerFromTo(_wheelParticle, 0.4, {
       opacity: 0,
       x: 0,
       y: 0,
       force3D: true,
       scale: 1,
     }, {
       opacity: 1,
       x: -40,
       y: -10,
       scale: 0.3,
       force3D: true,
       ease: Power0.easeNone
     }, 0.2);
     return tl;
   }

   // MASTER SCENES

   var cyclist = new TimelineMax({
     repeat: -1,
     repeatDelay: 0
   });

   cyclist.add(cyclo(_legsRight, -65, -30), "scene1")
     .add(cyclo(_legsLeft, -30, -65), "-=2");
   cyclist.timeScale(1);

   var master = new TimelineMax({
     repeat: -1,
     repeatDelay: 0
   });

   master.add(rotateWheel(), "scene1");
   master.timeScale(1);

   var backMaster = new TimelineMax({
     repeat: -1,
     repeatDelay: 0
   });

   backMaster.add(backgroundMove(), "scene1");
   backMaster.timeScale(1);

   var particleMaster = new TimelineMax({
     repeat: -1,
     paused: true
   });

   particleMaster.add(wheelParticle(), "scene1");
   particleMaster.timeScale(1);

   function bikeVelocity(obj) {
     leftRightBike((_world._gsTransform.rotation * 4));
     rotateTree(-(_world._gsTransform.rotation));
     if (_world._gsTransform.rotation < 0) {
       cyclist.timeScale((_world._gsTransform.rotation / 10) + 1);
       master.timeScale(Math.abs((-(_world._gsTransform.rotation / obj.maxX) - 1)));
       backMaster.timeScale(Math.abs((-(_world._gsTransform.rotation / obj.maxX) - 1)));
       particleMaster.pause(0);
       headerCyclo(_world._gsTransform.rotation);
     } else if (_world._gsTransform.rotation > 0) {
       particleMaster.play(0);
       cyclist.timeScale((_world._gsTransform.rotation / 10) + 1);
       master.timeScale((_world._gsTransform.rotation / 10) + 1);
       backMaster.timeScale((_world._gsTransform.rotation / 10) + 1);
       headerCyclo(-(_world._gsTransform.rotation));
     }
   }

   Draggable.create(_world, {
     type: "rotation",
     bounds: {
       minRotation: -40,
       maxRotation: 40
     },
     onDrag: function() {
       bikeVelocity(this);
     },
     onRelease: function() {
       TweenMax.to(_world, 2, {
         rotation: 0,
         ease: Elastic.easeOut.config(0.5, 0.7)
       });
       master.timeScale(1);
       cyclist.timeScale(1);
       backMaster.timeScale(1);
       particleMaster.pause(0);
       leftRightBike(0);
       headerCyclo(0);
       TweenMax.to(_tree, 2, {
         rotation: 0,
         ease: Elastic.easeOut.config(0.5, 0.7)
       })
     }
   });

 };

 window.onload = initAnimation;
              
            
!
999px

Console