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 class="canvas">
  <!-- Manually change viewBox width to 780px -->
  
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 780 439.6">
    <title>Awesome</title>
  <g>
    <g id="Deck">
      <path d="M10.89 412.6l351.5.5q9.14 0 9.14 7.14t-9.14 7.14H10.89q-9.39 0-9.39-7.39t9.39-7.39z" fill="#ececec" fill-opacity=".5" stroke="#b7b7b7" stroke-linecap="square" stroke-width="3" fill-rule="evenodd"/>
      <circle cx="186.89" cy="420.1" r="6.5" fill="#fff" fill-opacity=".66" stroke="#878787" stroke-width="2"/>
      <circle cx="98.14" cy="420.1" r="6.5" fill="#fff" fill-opacity=".66" stroke="#878787" stroke-width="2"/>
      <circle cx="9.39" cy="420.1" r="6.5" fill="#fff" fill-opacity=".66" stroke="#878787" stroke-width="2"/>
      <circle cx="364.39" cy="420.1" r="6.5" fill="#fff" fill-opacity=".66" stroke="#878787" stroke-width="2"/>
      <circle cx="275.64" cy="420.1" r="6.5" fill="#fff" fill-opacity=".66" stroke="#878787" stroke-width="2"/>
    </g>
    <g id="Crane">
      <g id="Crane-Boom">
        <path fill="#7d8075" fill-rule="evenodd" d="M671.59 212.24L606.23 58.03l-9.87 4.2 65.35 154.21 9.88-4.2z"/>
        <path d="M605.84 44.63l5.92 14-21.5 9.14c-9-2-11.14-6.16-5.92-14z" transform="translate(-4.5 -.4)" fill="#fcdd44" fill-rule="evenodd"/>
        <circle id="Crane-Hook" cx="585.23" cy="59.41" fill="#7d8075" r="3.79"/>
        <path fill="#fcdd44" fill-rule="evenodd" d="M740.42 366.46L654.6 163.95l-16.27 6.91 85.82 202.51 16.27-6.91z"/>
      </g>
      <g id="Crane-Body">
        <path d="M653.46 365.12h-49.79c-1.95 0-5.6 0-7.41 7.19q-.59 2.26 0 23.44h57.2z" transform="translate(-4.5 -.4)" fill="#fcdd44" fill-rule="evenodd"/>
        <path fill="#ffcb4e" d="M644.56 364.73h4.4v18.75h-4.4z"/>
        <path d="M619.33 380.62h135.84l10.18 14.22h5.15v5.87h-175v-18.27h2.62v12.4h10.56z" transform="translate(-4.5 -.4)" fill="#7d8075" stroke="#696b64" fill-rule="evenodd"/>
        <path fill="#696b64" fill-rule="evenodd" d="M759.59 400.85l-11.74-15.5h-41.69l-2.59 11.7h-7.22l-2.6-11.7h-22.78l-3.03 11.7h-7.35l-2.94-11.7H617.2l-12.34 15.5h154.73z"/>
        <ellipse cx="741.36" cy="396.6" rx="10.06" ry="10" fill="#7d8075"/>
        <ellipse cx="741.36" cy="396.6" rx="5.03" ry="5" fill="#dbdbdb"/>
        <ellipse cx="717.47" cy="396.6" rx="10.06" ry="10" fill="#7d8075"/>
        <ellipse cx="717.47" cy="396.6" rx="5.03" ry="5" fill="#dbdbdb"/>
        <ellipse cx="682.27" cy="396.6" rx="10.06" ry="10" fill="#7d8075"/>
        <ellipse cx="682.27" cy="396.6" rx="5.03" ry="5" fill="#dbdbdb"/>
        <ellipse cx="647.07" cy="396.6" rx="10.06" ry="10" fill="#7d8075"/>
        <ellipse cx="647.07" cy="396.6" rx="5.03" ry="5" fill="#dbdbdb"/>
        <ellipse cx="623.19" cy="396.6" rx="10.06" ry="10" fill="#7d8075"/>
        <ellipse cx="623.19" cy="396.6" rx="5.03" ry="5" fill="#dbdbdb"/>
        <path d="M613.86 378.25v-10h-8.6c-4.07 0-5.69 2-5.69 5v5z" transform="translate(-4.5 -.4)" fill="#696b64" fill-rule="evenodd"/>
        <path fill="#f2f2f2" d="M594.27 381.6h7.54v3.75h-7.54z"/>
        <path fill="#ffcb4e" d="M703.64 374.73h37.71v5h-37.71z"/>
        <path fill="#fcdd44" fill-rule="evenodd" d="M752.04 359.73h-12.25v-6.08l-23.73-7.05h-16.82v28.13h52.8v-15z"/>
        <path fill="#ffcb4e" d="M739.47 363.48h8.8v8.13h-8.8z"/>
        <path fill="#ffcb4e" d="M707.41 365.98h8.8v3.75h-8.8z"/>
        <path fill="#ffcb4e" d="M712.44 349.1h3.77v11.88h-3.77z"/>
        <path fill="#696b64" d="M699.24 349.1h13.2v11.88h-13.2z"/>
        <path fill="#7d8075" d="M699.24 350.98h4.4v10h-4.4z"/>
        <path d="M750.89 361.07V343.6c0-4.4-7.57-9.29-10.36-4.85q-6.39 10.19-15.41 22.32z" transform="translate(-4.5 -.4)" fill="#ffcb4e" fill-rule="evenodd"/>
      </g>
      <g id="Crane-Winch">
        <path id="Upper-Cable-1" fill="#c5c5c5" d="M593.5 61.6h3v49h-3z"/>
        <path id="Upper-Cable-2" fill="#c5c5c5" d="M580.5 61.6h3v49h-3z"/>
        <path id="Lower-Cable" fill="#c5c5c5" d="M587.5 118.6h3v95h-3z"/>
        <g id="Cable-Hook" fill="#c5c5c5" fill-rule="evenodd">
          <path id="Lower-Cable-2" data-name="Lower-Cable" d="M590.37 212.87l-2.74 1.58 12.63 21.88 2.74-1.58-12.63-21.88z"/>
          <path id="Lower-Cable-3" data-name="Lower-Cable" d="M587.63 212.87l2.74 1.58-12.63 21.88-2.74-1.58 12.63-21.88z"/>
        </g>
        <path id="Winch" fill="#fcdd44" fill-rule="evenodd" d="M599.5 108.6h-22v5.79l4.53 4.21h11.65l5.82-4.21v-5.79z"/>
      </g>
    </g>
    <g id="Final-Letters" fill="#2a2a2a">
      <path id="final_A" d="M50.72 363L70 413H57.84l-3.07-8.47H33.31L30.16 413H18l19.36-50zM44 373.64l-7.81 21.52h15.65z" transform="translate(-4.5 -.4)"/>
      <path id="final_w" d="M86.84 412.6l7.7-24.52 7.69 24.52h10.18l11.09-36h-9.96l-6.78 24.23-8-24.23h-8.52l-8 24.23-6.78-24.23H65.5l11.09 36h10.25z"/>
      <path id="final_e1" d="M150.8 376c10.83 0 18.2 8.09 18.2 19.94V398h-27c.6 4.57 4.29 8.39 10.46 8.39 3.08 0 7.37-1.35 9.7-3.6l4.21 6.15c-3.61 3.3-9.33 5-15 5-11.05 0-19.4-7.42-19.4-19C132 384.47 139.75 376 150.8 376zm0 7.57c-5.94 0-8.5 4.42-9 8h17.9c-.18-3.43-2.58-8-8.9-8z" transform="translate(-4.5 -.4)"/>
      <path id="final_s" d="M191.26 414c10.09 0 15.74-5 15.74-11.62 0-9.07-8.36-10.79-14.61-12-4.06-.82-6.92-1.42-6.92-3.52s2.25-3.6 5.72-3.6a15.38 15.38 0 0110.77 4.2l3.84-6.46a23.31 23.31 0 00-14.69-5c-9.56 0-14.91 5.32-14.91 11.39 0 8.7 8.06 10.27 14.31 11.47 4 .75 7.3 1.42 7.3 3.9 0 2.25-1.95 3.89-6.09 3.89a20.91 20.91 0 01-12.58-4.94l-4.14 6.67c3.84 3.52 9.94 5.62 16.26 5.62z" transform="translate(-4.5 -.4)"/>
      <path id="final_o" d="M233 376c11.9 0 19 8.69 19 19s-7.14 19-19 19-19-8.69-19-19 7.14-19 19-19zm0 8.47c-5.87 0-9.14 4.87-9.14 10.49s3.27 10.57 9.14 10.57 9.22-4.87 9.22-10.57-3.38-10.49-9.22-10.49z" transform="translate(-4.5 -.4)"/>
      <path id="final_m" d="M270.61 413v-24.29a9.82 9.82 0 017.56-4.26c3.94 0 5.45 2.39 5.45 5.75V413h9.68v-24.37a9.74 9.74 0 017.57-4.18c3.93 0 5.45 2.39 5.45 5.75V413H316v-26.09c0-7.4-4-10.91-10.74-10.91a15.56 15.56 0 00-12.56 6.58c-1.36-4.11-4.77-6.58-10.14-6.58-5.6 0-10.44 3.44-11.95 5.61v-4.71H261V413z" transform="translate(-4.5 -.4)"/>
      <path id="final_e2" d="M342.8 376c10.83 0 18.2 8.09 18.2 19.94V398h-27c.6 4.57 4.29 8.39 10.46 8.39 3.08 0 7.37-1.35 9.7-3.6l4.21 6.15c-3.61 3.3-9.33 5-15 5-11 0-19.4-7.42-19.4-19C324 384.47 331.75 376 342.8 376zm0 7.57c-5.94 0-8.5 4.42-8.95 8h17.9c-.23-3.43-2.63-8-8.95-8z" transform="translate(-4.5 -.4)"/>
    </g>
    <g id="Helicopter">
      <path id="Blades" d="M758.12 22.34a1.38 1.38 0 011 .4 1.36 1.36 0 01.41 1 1.5 1.5 0 01-1.45 1.5l-46.64 1.49-47.44-1.5a1.5 1.5 0 01-1-.46 1.54 1.54 0 01-.42-1.1 1.35 1.35 0 01.44-1 1.4 1.4 0 011-.37L711 23.83z" transform="translate(-4.5 -.4)" fill="#7d8075" stroke="#696b64" fill-rule="evenodd"/>
      <path id="Lower-Cable-4" data-name="Lower-Cable" fill="#c5c5c5" d="M697.5 60.6h2v30h-2z"/>
      <g id="Cable-Hook-2" data-name="Cable-Hook" fill="#c5c5c5" fill-rule="evenodd">
        <path id="Lower-Cable-5" data-name="Lower-Cable" d="M699.25 89.76l-1.5.92 3.96 12.76 1.51-.92-3.97-12.76z"/>
        <path id="Lower-Cable-6" data-name="Lower-Cable" d="M697.75 89.76l1.5.92-3.96 12.76-1.51-.92 3.97-12.76z"/>
      </g>
      <path fill="silver" d="M706.5 26.6h1v7h-1z"/>
      <path fill="silver" d="M703.5 26.6h1v7h-1z"/>
      <path fill="silver" d="M709.5 26.6h1v7h-1z"/>
      <path fill="silver" d="M715.5 65.6h1v4h-1z"/>
      <path fill="silver" d="M680.5 65.6h1v4h-1z"/>
      <path d="M729.06 32h-32a7 7 0 00-6.56 4.57l-.91 2.43a5 5 0 004.87 6.67l34.6-1.52a6.22 6.22 0 005.94-6.21 5.94 5.94 0 00-5.94-5.94z" transform="translate(-4.5 -.4)" fill="#fcdd44" fill-rule="evenodd"/>
      <path fill="#ffcb4e" fill-rule="evenodd" d="M763.83 37.6H683.5v12h52.79l30.21-3.67-2.67-8.33z"/>
      <path d="M782.85 23.39q-3.39-1.47-7.93 7.9l8.16 3.31q3.17-9.73-.23-11.21z" transform="translate(-4.5 -.4)" fill="#ffcb4e" fill-rule="evenodd"/>
      <path d="M773 28.6a10.25 10.25 0 00-7.41 3.21 11.36 11.36 0 000 15.58 10.16 10.16 0 0014.82 0 11.36 11.36 0 000-15.58A10.25 10.25 0 00773 28.6zm0 7a3.78 3.78 0 012.75 1.19 4.06 4.06 0 010 5.62 3.77 3.77 0 01-5.5 0 4.06 4.06 0 010-5.62A3.78 3.78 0 01773 35.6z" fill="#7d8075" stroke="#696b64" stroke-width="2" fill-rule="evenodd"/>
      <path d="M740 49h-58.68a8.31 8.31 0 00-8.32 8.32v.18a8.51 8.51 0 008.5 8.5h40.42a11.49 11.49 0 009.35-4.81z" transform="translate(-4.5 -.4)" fill="#fcdd44" fill-rule="evenodd"/>
      <path d="M728 56h-16a5 5 0 00-5 5 5 5 0 005 5h16a5 5 0 005-5 5 5 0 00-5-5z" transform="translate(-4.5 -.4)" fill="#ffcb4e" fill-rule="evenodd"/>
      <path d="M682 56h-1a4 4 0 00-4 4 4 4 0 004 4h1a4 4 0 004-4 4 4 0 00-4-4z" transform="translate(-4.5 -.4)" fill="#ffcb4e" fill-rule="evenodd"/>
      <circle cx="716" cy="71.1" r="2" fill="#7d8075" stroke="#696b64"/>
      <circle cx="681" cy="71.1" r="2" fill="#7d8075" stroke="#696b64"/>
      <path d="M681.16 50h13.3q8-3.8 9.54-12h-15.41q-8.7 3.71-7.43 12z" transform="translate(-4.5 -.4)" fill="#7d8075" stroke="#696b64" fill-rule="evenodd"/>
    </g>
    <path id="A" d="M399.58 411.61l-53.58 1 4.16-11.43h9l7.35-20.18-6.88-5.85 4.16-11.43 40.36 35.3zm-7.72-9.92L374.32 387 369 401.67z" transform="translate(-4.5 -.4)" fill="#2a2a2a"/>
    <path id="w" fill="#2a2a2a" d="M690.85 138.6l7.69-24.52 7.69 24.52h10.18l11.09-36h-9.96l-6.78 24.23-8-24.23h-8.52l-8 24.23-6.78-24.23h-9.96l11.09 36h10.26z"/>
    <path id="s" d="M593.26 268c10.09 0 15.74-5 15.74-11.62 0-9.07-8.36-10.79-14.61-12-4.06-.82-6.92-1.42-6.92-3.52s2.25-3.6 5.72-3.6a15.38 15.38 0 0110.77 4.2l3.84-6.46a23.31 23.31 0 00-14.69-5c-9.56 0-14.91 5.32-14.91 11.39 0 8.7 8.06 10.27 14.31 11.47 4 .75 7.3 1.42 7.3 3.9 0 2.25-1.95 3.89-6.09 3.89a20.91 20.91 0 01-12.58-4.94l-4.14 6.67c3.84 3.52 9.94 5.62 16.26 5.62z" transform="translate(-4.5 -.4)" fill="#2a2a2a"/>
    <path id="o" d="M1025 375c11.9 0 19 8.69 19 19s-7.14 19-19 19-19-8.69-19-19 7.14-19 19-19zm0 8.47c-5.87 0-9.14 4.87-9.14 10.49s3.27 10.57 9.14 10.57 9.22-4.87 9.22-10.57-3.38-10.49-9.22-10.49z" transform="translate(-4.5 -.4)" fill="#2a2a2a"/>
    <path id="e2" d="M961.8 376c10.83 0 18.2 8.09 18.2 19.94V398h-27c.6 4.57 4.29 8.39 10.46 8.39 3.08 0 7.37-1.35 9.7-3.6l4.21 6.15c-3.61 3.3-9.33 5-15 5-11 0-19.4-7.42-19.4-19C943 384.47 950.75 376 961.8 376zm0 7.57c-5.94 0-8.5 4.42-8.95 8h17.9c-.23-3.43-2.63-8-8.95-8z" transform="translate(-4.5 -.4)" fill="#2a2a2a"/>
    <path id="e1" d="M816.8 376c10.83 0 18.2 8.09 18.2 19.94V398h-27c.6 4.57 4.29 8.39 10.46 8.39 3.08 0 7.37-1.35 9.7-3.6l4.21 6.15c-3.61 3.3-9.33 5-15 5-11 0-19.4-7.42-19.4-19C798 384.47 805.75 376 816.8 376zm0 7.57c-5.94 0-8.5 4.42-8.95 8h17.9c-.23-3.43-2.63-8-8.95-8z" transform="translate(-4.5 -.4)" fill="#2a2a2a"/>
    <path id="Clip-Path" fill="none" d="M1113.5 439.6H782.45V331.06L1113.5 0v439.6z"/>
    <path id="m" d="M870.61 414v-24.29a9.82 9.82 0 017.56-4.26c3.94 0 5.45 2.39 5.45 5.75V414h9.68v-24.37a9.74 9.74 0 017.57-4.18c3.93 0 5.45 2.39 5.45 5.75V414H916v-26.09c0-7.4-4-10.91-10.74-10.91a15.56 15.56 0 00-12.56 6.58c-1.36-4.11-4.77-6.58-10.14-6.58-5.6 0-10.44 3.44-11.95 5.61v-4.71H861V414z" transform="translate(-4.5 -.4)" fill="#2a2a2a"/>
    <g id="Dumper">
      <g id="Dumper-Cab">
        <path fill="#7d8075" d="M495.58 366.94h11.03v11h-11.03z"/>
        <path fill="#7d8075" d="M449.98 352.27h37.51v25.67h-37.51z"/>
        <path fill="#696b64" d="M449.98 354.47h25.74v21.27h-25.74z"/>
        <path fill="#7d8075" d="M498.52 360.34h5.15v8.07h-5.15z"/>
        <path fill="#fcdd44" d="M439.68 375.74h72.82v15.4h-72.82z"/>
        <path fill="#fcdd44" d="M434.53 369.87h15.45v21.27h-15.45z"/>
        <path fill="#fcdd44" d="M423.5 388.2h21.33v15.4H423.5z"/>
        <path fill="#fcdd44" d="M444.83 348.6h47.07v5.87h-47.07z"/>
      </g>
      <g id="Dumper-Base">
        <path d="M511.73 414v-.09c6.89-.72 13.27-5.7 13.27-16.41s-6.38-15.69-13.27-16.41V381h-58.25c-7.52 0-15 4.88-15 16.5s7.52 16.5 15 16.5h58.25z" transform="translate(-4.5 -.4)" fill="#7d8075" fill-rule="evenodd"/>
        <path d="M505.09 409.5v-.06c5.74-.51 11.06-4 11.06-11.56s-5.32-11.06-11.06-11.57v-.06h-47.92c-6 .26-11.8 3.74-11.8 11.61s5.79 11.34 11.8 11.6z" transform="translate(-4.5 -.4)" fill="#696b64" fill-rule="evenodd"/>
        <ellipse cx="502.07" cy="397.1" rx="11.06" ry="11.25" fill="#fcdd44"/>
        <ellipse cx="502.07" cy="397.1" rx="5.9" ry="6" fill="#ffcb4e"/>
        <ellipse cx="484.37" cy="401.6" rx="6.64" ry="6.75" fill="#fcdd44"/>
        <ellipse cx="484.37" cy="401.6" rx="3.69" ry="3.75" fill="#ffcb4e"/>
        <ellipse cx="469.63" cy="401.6" rx="6.64" ry="6.75" fill="#fcdd44"/>
        <ellipse cx="469.63" cy="401.6" rx="3.69" ry="3.75" fill="#ffcb4e"/>
        <ellipse cx="451.93" cy="397.1" rx="11.06" ry="11.25" fill="#fcdd44"/>
        <ellipse cx="451.93" cy="397.1" rx="5.9" ry="6" fill="#ffcb4e"/>
      </g>
      <g id="Dumper-Bucket" fill-rule="evenodd">
        <path d="M441.05 367.4L417.69 396a4 4 0 00.56 5.67A4.12 4.12 0 00424 401l23.36-28.55a4 4 0 00-.57-5.67 4.1 4.1 0 00-5.74.62z" transform="translate(-4.5 -.4)" fill="#696b64"/>
        <path d="M414.36 414H398q14.91-37.5 16.36-37.5c9.37 0 17.81 8.39 17.81 18.75S424.2 414 414.36 414z" transform="translate(-4.5 -.4)" fill="#7d8075"/>
      </g>
    </g>
  </g>
  <g id="Replay">
    <path fill="#FFFFFF" opacity="0.5" d="M377.27 317.69h30.05v30.05h-30.05z"/>
    <path d="M407.35 329.8a9.86 9.86 0 00-1.83-3.07l1.49-1.59-3.72-.88-3.73-.87 1.09 3.63v.07l1.08 3.59 1.5-1.6a6.89 6.89 0 011 1.82 6.71 6.71 0 11-8.63-4h.07l-.88-3.15-.32.11a10 10 0 1012.82 5.88z" transform="translate(-4.5 -.4)" fill="#474747"/>
  </g>
</svg>

</div>
              
            
!

CSS

              
                .canvas svg {
  height: 400px;
}

#final_A, #final_w, #final_e1, #final_s, #final_o, #final_m, #final_e2 { opacity: 0; }

#Replay {
  opacity: 0;
  cursor: pointer;
  
  &:hover path:last-child {
    fill: #EF7602;
  }
}

@keyframes spin {
  from {
    transform:rotateY(0deg);
  }

  to {
     transform:rotateY(-360deg);
  }
}

#Blades {
  perspective: 500px;
  transform-origin: 706px 0; // Initial x position of helicopter
  transform-style: preserve-3d;
  animation-duration: 0.3s;
  animation-name: spin;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
  animation-play-state: running;
}
              
            
!

JS

              
                var canvas = document.querySelector(".canvas")

gsap.registerPlugin(MotionPathPlugin)

function getBBoxDiff(element, withoutTransforms, toElement) {
  
  var svg = element.ownerSVGElement;
  
  if (!svg) {
    return { x: 0, y: 0, width: 0, height: 0 };
  }
    
  if (withoutTransforms) {
    return element.getBBox();
  }
  
  var p = svg.createSVGPoint();
  var r = element.getBBox();     
      
  var matrix = (toElement || svg).getScreenCTM().inverse().multiply(element.getScreenCTM()); 

  p.x = r.x;
  p.y = r.y;
  var a = p.matrixTransform(matrix);

  p.x = r.x + r.width;
  p.y = r.y;
  var b = p.matrixTransform(matrix);

  p.x = r.x + r.width;
  p.y = r.y + r.height;
  var c = p.matrixTransform(matrix);

  p.x = r.x;
  p.y = r.y + r.height;
  var d = p.matrixTransform(matrix);

  var minX = Math.min(a.x, b.x, c.x, d.x);
  var maxX = Math.max(a.x, b.x, c.x, d.x);
  var minY = Math.min(a.y, b.y, c.y, d.y);
  var maxY = Math.max(a.y, b.y, c.y, d.y);
    
  var width = maxX - minX;
  var height = maxY - minY;
  
  return {
    x: minX,
    y: minY,
    width: width,
    height: height,        
    cx: minX + width / 2,
    cy: minY + height / 2
  };
}

var letters = {
  A: document.querySelector("#A"),
  w: document.querySelector("#w"),
  e1: document.querySelector("#e1"),
  s: document.querySelector("#s"),
  o: document.querySelector("#o"),  
  m: document.querySelector("#m"),
  e2: document.querySelector("#e2")
}
var destinations = {
  A: document.querySelector("#final_A"),
  w: document.querySelector("#final_w"),
  e1: document.querySelector("#final_e1"),
  s: document.querySelector("#final_s"),
  o: document.querySelector("#final_o"),  
  m: document.querySelector("#final_m"),
  e2: document.querySelector("#final_e2")
}

const Deck = document.querySelector("#Deck")
var Helicopter = document.querySelector("#Helicopter")
var Blades = document.querySelector("#Blades")
var Dumper = document.querySelector("#Dumper")
var Bucket = document.querySelector("#Dumper-Bucket")
var Crane = document.querySelector("#Crane")
var CraneBody = document.querySelector("#Crane-Body")
var CraneBoom = document.querySelector("#Crane-Boom")
const CraneHook = document.querySelector("#Crane-Hook")
const CraneCable = document.querySelector("#Crane-Winch")
const ReplyButton = document.querySelector("#Replay")

var DUMPER_W = Dumper.getBBox().width
var HELI_W = Helicopter.getBBox().width

var dumperTimeline = () => {
  var tl = gsap.timeline({ repeat: 0 })
  tl.addLabel("standA")

  const Ax = destinations.A.getBBox().x + A.getBBox().width
  
  tl.add(gsap.to(A, {
    duration: 2,
    x: -(A.getBBox().x - Ax + 10)
  }), "standA")
  
  tl.add(gsap.to(Dumper, {
    duration: 2, x: -(Dumper.getBBox().x - Ax) + 40
  }), "standA")
  
  tl.add(gsap.to(A, {
    duration: 0.6,
    rotation: -65,
    ease: 'linear'
  }), "standA+=1")
  
  tl.add(gsap.to(A, {
    duration: 0.3,
    rotation: -110,
    ease: 'power1.in'
  }), "standA+=1.6")
  
  tl.add(gsap.to(Bucket, {
    rotation: 45,
    duration: 0.6,
    ease: 'linear'
  }), "standA+=1")
  
  tl.addLabel("prepareE1")
  
  tl.add(gsap.to(Dumper, {
    duration: 2.5,
    x: letters.e1.getBBox().x - Dumper.getBBox().x + 15,
    ease: "power1.inOut"
  }), "prepareE1")
  
  tl.add(gsap.to(Bucket, {
    rotation: 0,
    duration: 1,
    ease: 'linear'
  }), "prepareE1+=0.5")
  
  tl.addLabel("enterE1")
  tl.add(gsap.to(Bucket, {
    rotation: 20,
    duration: 0.5,
    ease: 'linear'
  }), "enterE1")
  
  tl.add(gsap.to(letters.e1, {
    y: -18,
    duration: 0.5,
    ease: 'linear'
  }), "enterE1")
  
  const Ex = destinations.e1.getBBox().x + e1.getBBox().width
  
  tl.add(gsap.to(Dumper, {
    duration: 2.5,
    x: -(Dumper.getBBox().x - Ex + (e1.getBBox().width / 2)) - 5,
    ease: "power1.out"
  }), "enterE1+=0.5")
  
  tl.add(gsap.to(letters.e1, {
    duration: 2.5,
    x: -(letters.e1.getBBox().x - destinations.e1.getBBox().x) - 5,
    ease: "power1.out"
  }), "enterE1+=0.5")
  
  tl.addLabel("placeE1")
  tl.add(gsap.to(Bucket, {
    rotation: 0,
    duration: 0.4,
    ease: 'linear'
  }), "placeE1")
  
  tl.add(gsap.to(letters.e1, {
    y: -1,
    duration: 0.4,
    ease: 'linear'
  }), "placeE1")
  
  // Move to pickup m
  
  tl.add(gsap.to(Dumper, {
    duration: 2.5,
    x: letters.m.getBBox().x - Dumper.getBBox().x + 30,
    ease: "power1.inOut"
  }), "placeE1+=0.5")
  
  tl.addLabel("enterM")
  
  const Mx = destinations.m.getBBox().x + m.getBBox().width
  
  tl.add(gsap.to(Dumper, {
    duration: 3.5,
    x: -(Dumper.getBBox().x - Mx - 60),
    ease: "power1.inOut"
  }), "enterM+=0.5")
  
  tl.add(gsap.to(letters.m, {
    duration: 3.5,
    y: "-=2",
    x: -(letters.m.getBBox().x - Mx - 20),
    ease: "power1.inOut"
  }), "enterM+=0.5")
  
  // Move to roll in e
  tl.add(gsap.to(Dumper, {
    duration: 2.5,
    x: letters.e2.getBBox().x - Dumper.getBBox().x + 10,
    ease: "power1.inOut"
  }), "enterM+=3.5")
  
  tl.addLabel("enterE2", "+=1")
  
  tl.add(gsap.to(letters.e2, {
    duration: 0.8,
    repeat: 3,
    rotation: -360,
    ease: "linear"
  }), "enterE2")
  
  tl.add(gsap.to(letters.e2, {
    duration: 4,
    x: destinations.e2.getBBox().x - letters.e2.getBBox().x - 8,
    ease: "power2.inOut"
  }), "enterE2")
  
  tl.add(gsap.to(Dumper, {
    duration: 3.75, // Manually sync
    x: -(Dumper.getBBox().x - destinations.e2.getBBox().x) + 100,
    ease: "power2.inOut"
  }), "enterE2")
  
  // Animate final roll separately
  tl.add(gsap.to(letters.e2, {
    duration: 1,
    rotation: -360,
    ease: "power2.in"
  }), "enterE2+=3.8")
  
  tl.add(gsap.to(Dumper, {
    x: 1000,
    duration: 4,
    ease: "power1.inOut"
  }), "enterE2+=4.5")
  
  return tl
}

var helicopterTimeline = () => {
  var tl = gsap.timeline({ repeat: 0 })
  tl.addLabel("lowerW")
  
  let destX = destinations.w.getBBox().x
  let destY = destinations.w.getBBox().y
  
  tl.add(gsap.to(Helicopter, {
    motionPath: {
      path: [{
        x: -(Helicopter.getBBox().x - (destX + 120)),
        y: -(Helicopter.getBBox().y - (destY - 220))
      }, {
        x: -(Helicopter.getBBox().x - (destX - 7)),
        y: -(Helicopter.getBBox().y - (destY - 76))
      }]
    },
    duration: 5,
    ease: "power1.inOut"
  }), "lowerW")
  
  tl.add(gsap.to(w, {
    motionPath: {
      path: [{
        x: -(Helicopter.getBBox().x - (destX + 120)),
        y: -(Helicopter.getBBox().y - (destY - 220))
      }, {
        x: -(w.getBBox().x - destX),
        y: -(w.getBBox().y - destY)
      }]
    },
    duration: 5,
    ease: "power1.inOut"
  }), "lowerW")
  
  tl.add(gsap.to(Helicopter, {
    delay: 1,
    motionPath: {
      path: [{
        x: -(Helicopter.getBBox().x - (destX + 40)),
        y: -(Helicopter.getBBox().y - (destY - 220))
      }, {
        x: 0,
        y: 0
      }]
    },
    duration: 4,
    ease: "power1.in"
  }))
  
  const oHeliOffsetX = 22
  const oHeliOffsetY = 78
  
  tl.add(gsap.to(Helicopter, {
    motionPath: {
      path: [{
        x: 0,
        y: 0
      }, {
        x: -(Helicopter.getBBox().x - (letters.o.getBBox().x - oHeliOffsetX)),
        y: -(Helicopter.getBBox().y - (letters.o.getBBox().y - oHeliOffsetY))
      }]
    },
    duration: 3,
    ease: "power1.out"
  }))
  
  destX = destinations.o.getBBox().x - 6 // Manually fix position
  destY = destinations.o.getBBox().y - 150
  
  tl.addLabel("moveO")
  
  tl.add(gsap.to(o, {
    motionPath: {
      path: [{
        x: -(o.getBBox().x - (destX + 120)),
        y: -(o.getBBox().y - destY)
      }, {
        x: -(o.getBBox().x - destX),
        y: -(o.getBBox().y - destY)
      }]
    },
    duration: 5,
    ease: "power1.inOut"
  }), "moveO")
  
  tl.add(gsap.to(Helicopter, {
    motionPath: {
      path: [{
        x: -(Helicopter.getBBox().x - (destX + 120 - oHeliOffsetX + 4)),
        y: -(Helicopter.getBBox().y - (destY - oHeliOffsetY))
      }, {
        x: -(Helicopter.getBBox().x - (destX - oHeliOffsetX + 4)),
        y: -(Helicopter.getBBox().y - (destY - oHeliOffsetY))
      }]
    },
    duration: 5,
    ease: "power1.inOut"
  }), "moveO")
  
  tl.addLabel("dropO")
  
  tl.add(gsap.to(o, {
    x: -(o.getBBox().x - destX),
    y: -(o.getBBox().y - (destinations.o.getBBox().y - 2)),
    duration: 1,
    ease: "bounce.out"
  }), "dropO+=0.25")
  
  // Pause and just hover around
  
  tl.addLabel("heliHover")
  
  tl.add(gsap.to(Helicopter, {
    rotation: -10,
    duration: 0.5,
    ease: "power1.inOut"
  }), "heliHover")
  
  tl.add(gsap.to(Helicopter, {
    x: "-=180",
    y: "-=40",
    duration: 2,
    ease: "power1.inOut"
  }), "heliHover+=0.2")
  
  tl.add(gsap.to(Helicopter, {
    rotation: 0,
    duration: 0.5,
    ease: "power1.inOut"
  }), "heliHover+=1.2")
  
  // Move back, still just hovering
  tl.add(gsap.to(Helicopter, {
    rotation: 10,
    duration: 0.5,
    ease: "power1.inOut"
  }), "heliHover+=3")
  
  tl.add(gsap.to(Helicopter, {
    x: "+=180",
    y: "-=30",
    duration: 2,
    ease: "power1.inOut"
  }), "heliHover+=3.2")
  
  tl.add(gsap.to(Helicopter, {
    rotation: 0,
    duration: 0.5,
    ease: "power1.inOut"
  }), "heliHover+=4.2")
  
  tl.add(gsap.to(Helicopter, {
    y: "-=100",
    opacity: "0",
    duration: 2,
    ease: "power1.inOut"
  }), "heliHover+=6")
  
  return tl
}

var craneTimeline = () => {
  var tl = gsap.timeline({ repeat: 0 })
  tl.addLabel("enterS")
  
  const bindCraneCable = () => {
    const cable = getBBoxDiff(CraneCable)
    const hook = getBBoxDiff(CraneHook)
    
    let dx = hook.cx - cable.cx
    let dy = hook.cy - cable.y
      
    gsap.set(CraneCable, {
      x: `+=${dx}`,
      y: `+=${dy}`,
    })
  }
  
  const bindCraneLetter = (target) => {
    const cable = getBBoxDiff(CraneCable)
    const hook = getBBoxDiff(CraneHook)
    const letter = getBBoxDiff(target)
      
    let dx = hook.cx - letter.cx
    let dy = hook.cy - letter.y + cable.height - 7

    gsap.set(target, {
      x: `+=${dx}`,
      y: `+=${dy}`,
    })
  }
  
  tl.add(gsap.to(Crane, {
    x: -255,
    duration: 6,
    ease: "sine.inOut",
    onStart: function() {
      bindCraneCable()
      bindCraneLetter(letters.s)
    },
    onUpdate: function() {
      bindCraneCable()
      bindCraneLetter(letters.s)
    }
  }), "enterS")
  
  tl.add(gsap.to(CraneBoom, {
    rotation: -38.5,
    duration: 4,
    ease: "sine.inOut",
    onUpdate: function() {
      bindCraneCable()
      bindCraneLetter(letters.s)
    }
  }), "enterS+=7")
  
  tl.add(gsap.to(CraneBoom, {
    rotation: -20,
    duration: 4,
    ease: "sine.inOut",
    onUpdate: function() {
      bindCraneCable()
    }
  }))
  
  tl.add(gsap.to(Crane, {
    x: -76,
    duration: 5,
    ease: "sine.inOut"
  }), "enterS+=11")
  
  // After dumper has moved in m (enterM + 4), move it
  tl.addLabel("collectM", "enterM-=1")
  
  tl.add(gsap.to(CraneBoom, {
    rotation: -38.5,
    duration: 2,
    ease: "sine.inOut",
    onUpdate: function() {
      bindCraneCable()
    }
  }), "collectM")
  
  tl.add(gsap.to(CraneBoom, {
    rotation: -30,
    duration: 1.5,
    ease: "sine.inOut",
    onUpdate: function() {
      bindCraneCable()
      bindCraneLetter(letters.m)
    }
  }), "collectM+=2.25")
  
  tl.addLabel("moveM")
  
  tl.add(gsap.to(Crane, {
    x: -160,
    duration: 2,
    ease: "sine.inOut",
    onUpdate: function() {
      bindCraneLetter(letters.m)
    }
  }), "moveM")
  
  // Lower m into proper position
  tl.add(gsap.to(CraneBoom, {
    rotation: -38.5,
    duration: 1.5,
    ease: "sine.inOut",
    onUpdate: function() {
      // Bind cable to crane hook
      const cable = getBBoxDiff(CraneCable)
      const hook = getBBoxDiff(CraneHook)

      let dx = hook.cx - cable.cx
      let dy = hook.cy - cable.y

      gsap.set(CraneCable, {
        x: `+=${dx}`,
        y: `+=${dy}`,
      })
      
      // Bind letter to bottom of crane cable
      const letter = getBBoxDiff(letters.m)
      
      dx = hook.cx - letter.cx
      dy = hook.cy - letter.y + cable.height - 7
      
      gsap.set(letters.m, {
        x: `+=${dx}`,
        y: `+=${dy}`,
      })
    }
  }), "moveM+=1.5")
  
  // Crane exits scene
  
  tl.add(gsap.to(CraneBoom, {
    rotation: -20,
    duration: 5,
    ease: "sine.inOut",
    onUpdate: function() {
      // Bind cable to crane hook
      const cable = getBBoxDiff(CraneCable)
      const hook = getBBoxDiff(CraneHook)

      let dx = hook.cx - cable.cx
      let dy = hook.cy - cable.y

      gsap.set(CraneCable, {
        x: `+=${dx}`,
        y: `+=${dy}`,
      })
    }
  }), "moveM+=3")
  
  tl.add(gsap.to(Crane, {
    x: 400,
    duration: 5,
    ease: "sine.inOut"
  }), "moveM+=3")
  
  return tl
}

const showControls = () => {
  var tl = gsap.timeline({ repeat: 0 })
  tl.addLabel("showControls")
  
  tl.add(gsap.to(ReplyButton, {
    opacity: 1,
    duration: 0.5
  }), "showControls")
  
  tl.add(gsap.to(Deck, {
    opacity: 0,
    duration: 0.5
  }), "showControls")
  
  return tl
}

// Setup scene

gsap.set(A, { transformOrigin: "bottom left" })
gsap.set(Bucket, { transformOrigin: "top right" })
gsap.set(Helicopter, { transformOrigin: "bottom center" })
gsap.set(CraneBoom, { transformOrigin: "90% 90%" })
gsap.set(CraneCable, { transformOrigin: "0% 50%" })
gsap.set(e2, { transformOrigin: "50% 50%" })

var master = gsap.timeline({ repeat: 0 })
master.add(dumperTimeline(), 0)
master.add(helicopterTimeline(), 0)
master.add(craneTimeline(), 0)

master.add(showControls())

master.play()

ReplyButton.addEventListener("click", (e) => {
  master.restart()
}, false)
              
            
!
999px

Console