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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <body>
<h2>Over-and-under pipe simulation</h2>
<p>On page-load, the 4 coloured circles follow the pink motion path anti-clockwise around the looped pipe (#motionPath is off the top of the screen - the circles don't line up with the pipe unless I place it there...?!). #ball1 - #ball4 each has a mask #crossoverMask1 - 4 which moves in to position when they are half way around the loop to hide them and make it appear as if they are going under the loop. The green shape shows the movement of #crossoverMask1.</p>
<p>Timing is randomised, so I need a mask for each circle in case a slow one is still in the "above" position when another is in the "under" position. An alternative solution might be to change the circles&rsquo; z-index, but this mask-moving method appears to work OK.</p>
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
 viewBox="0 2 160 80">
   <!-- find out how to universally scale / position svg. This is almost right. Always make SVGs 16x7ish because the browser uses up some of the vertical space of 16x9 -->
   <defs>
   <mask id="crossoverMask1">
   <path id="crossoverMaskHandler1" style="fill:#ffffff" d="M 1.639912,2.4147298 V 75.383477 H 151.17506 V 2.4147298 Z m 61.638658,44.4042942 3.2168,6.216797 c -8.607904,4.455461 -14.970692,4.96875 -14.970692,4.96875 l -0.490234,-6.982422 c 0,0 4.626234,-0.260091 12.244126,-4.203125 z" />
   </mask>
      <mask id="crossoverMask2">
   <path id="crossoverMaskHandler2" style="fill:#ffffff" d="M 1.639912,2.4147298 V 75.383477 H 151.17506 V 2.4147298 Z m 61.638658,44.4042942 3.2168,6.216797 c -8.607904,4.455461 -14.970692,4.96875 -14.970692,4.96875 l -0.490234,-6.982422 c 0,0 4.626234,-0.260091 12.244126,-4.203125 z" />
   </mask>
      <mask id="crossoverMask3">
   <path id="crossoverMaskHandler3" style="fill:#ffffff" d="M 1.639912,2.4147298 V 75.383477 H 151.17506 V 2.4147298 Z m 61.638658,44.4042942 3.2168,6.216797 c -8.607904,4.455461 -14.970692,4.96875 -14.970692,4.96875 l -0.490234,-6.982422 c 0,0 4.626234,-0.260091 12.244126,-4.203125 z" />
   </mask>
      <mask id="crossoverMask4">
   <path id="crossoverMaskHandler4" style="fill:#ffffff" d="M 1.639912,2.4147298 V 75.383477 H 151.17506 V 2.4147298 Z m 61.638658,44.4042942 3.2168,6.216797 c -8.607904,4.455461 -14.970692,4.96875 -14.970692,4.96875 l -0.490234,-6.982422 c 0,0 4.626234,-0.260091 12.244126,-4.203125 z" />
   </mask>
   </defs>
    <path
       style="fill:#ffaaaa;fill-opacity:.2;stroke:none;stroke-width:0;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
       d="M 1.592667,1.6048845 V 79.327454 H 158.40283 V 1.6048845 Z m 14.228094,6.2672799 c 5.960013,-2.01e-5 10.791566,4.8315306 10.791547,10.7915446 2.5e-5,5.960019 -4.831529,10.791577 -10.791547,10.791556 C 9.8607424,29.455285 5.02919,24.623728 5.0292152,18.663709 5.0291962,12.703695 9.8607474,7.8721447 15.820761,7.8721644 Z m 28.74287,0 c 5.960013,-2.01e-5 10.791566,4.8315306 10.791547,10.7915446 2.5e-5,5.960019 -4.831529,10.791577 -10.791547,10.791556 -5.960019,2.1e-5 -10.791572,-4.831537 -10.791547,-10.791556 -2e-5,-5.960014 4.831533,-10.7915647 10.791547,-10.7915446 z m 28.742881,0 c 5.959925,1.062e-4 10.791338,4.8316196 10.791318,10.7915446 2.5e-5,5.959929 -4.831389,10.79145 -10.791318,10.791556 C 67.346494,29.455286 62.51494,24.623728 62.514965,18.663709 62.514946,12.703695 67.346498,7.8721443 73.306512,7.8721644 Z M 15.820761,34.851147 c 5.959925,-2e-5 10.79144,4.831393 10.791547,10.791318 1.3e-5,5.960011 -4.831537,10.791556 -10.791547,10.791536 C 9.8607504,56.43402 5.0292013,51.602476 5.0292152,45.642465 5.0293214,39.68254 9.8608354,34.851128 15.820761,34.851147 Z m 28.74287,0 c 5.959925,-2e-5 10.79144,4.831393 10.791547,10.791318 1.3e-5,5.960011 -4.831537,10.791556 -10.791547,10.791536 -5.960011,2e-5 -10.791561,-4.831525 -10.791547,-10.791536 1.06e-4,-5.959925 4.831621,-10.791338 10.791547,-10.791318 z m 28.742881,0 c 5.959836,1.07e-4 10.791212,4.831482 10.791318,10.791318 1.4e-5,5.959921 -4.831397,10.791429 -10.791318,10.791536 -5.96001,2e-5 -10.79156,-4.831525 -10.791547,-10.791536 1.07e-4,-5.959925 4.831622,-10.791338 10.791547,-10.791318 z"
       id="rect815"
       inkscape:connector-curvature="0" />

	   <path id="pipe" style="fill:#fedbca;" d="m 98.623798,9.1013843 c -6.67916,0.142689 -12.59658,5.4401207 -13.89373,11.9244107 -1.75856,7.5282 0.36166,15.36183 
3.38959,22.27295 1.21688,2.63453 2.70866,5.155 4.56192,7.39398 -3.26855,0.73869 -6.59206,1.24678 -9.93735,1.45885 l 0.28125,6.96958 c 5.05641,-0.30577 10.07693,-1.18839 14.93733,-2.61475 4.045702,4.363 8.116722,8.70244 12.199062,13.03115 l 5.05505,-4.80635 c -3.42084,-3.63021 -6.83439,-7.2673 -10.23696,-10.91465 6.74343,-3.02639 12.80721,-8.9413 13.8101,-16.545 0.91275,-6.49543 -0.64293,-13.25904 -3.8787,-18.92049 -3.38708,-5.55573 -9.5992,-9.7293957 -16.287562,-9.2496807 z m 0.40727,6.9069907 c 6.067532,-0.15089 10.759032,5.29036 12.025902,10.83886 1.4217,5.00402 1.87976,11.06521 -1.75899,15.2766 -2.42708,2.9432 -5.85038,4.84909 -9.329682,6.28297 -4.85788,-4.89147 -7.49381,-11.62313 -8.59195,-18.33358 -0.0976,-6.54868 0.61305,-13.75075 7.65472,-14.06485 z"/>
	   
	   <path id="motionPath" style="fill:none;stroke:#facade;stroke-width:1px;" d="m -0.05446636,0.0084512 c 0,0 4.26117016,0.4668499 7.67858056,0.11457 8.7996498,-0.9070901 32.2537098,-5.73627 31.4241498,-22.3275402 -1.05904,-21.180807 -18.76012,-24.963087 -25.26564,-16.036894 -6.5055298,8.926194 0.15129,26.022115 5.44648,31.9224742 3.18934,3.55382 12.45361,12.92882 16.0086,17.2992698 3.54081,4.353031 9.83055,2.338101 9.83055,2.338101" />
   
   <!-- CrossoverMaskHandler1 is revealed here to demonstrate how the masks operate -->
   <path id="crossoverMaskHandler1" style="fill:none;opacity:.6;stroke-width:0.1px;stroke:#22ff22;" d="M 1.639912,2.4147298 V 75.383477 H 151.17506 V 2.4147298 Z m 61.638658,44.4042942 3.2168,6.216797 c -8.607904,4.455461 -14.970692,4.96875 -14.970692,4.96875 l -0.490234,-6.982422 c 0,0 4.626234,-0.260091 12.244126,-4.203125 z" />	   



   
<!-- balls -->
<g mask="url(#crossoverMask1)">
<g id="ball1">
	     <text
     xml:space="preserve"
     style="" class="ballText"
     x="75"
     y="57.6"
     id="text851">1</text>
<path style="fill:#abcdef; opacity: 0.6" d="m 80.840839,55.70118 a 3.8540533,3.9690995 0 0 1 -3.854053,3.969099 3.8540533,3.9690995 0 0 1 -3.854053,-3.969099 3.8540533,3.9690995 0 0 1 3.854053,-3.9691 3.8540533,3.9690995 0 0 1 3.854053,3.9691 z"/></g>
</g>

<g mask="url(#crossoverMask2)">
<g id="ball2">
	     <text
     xml:space="preserve"
     style="" class="ballText"
     x="75"
     y="57.6"
     id="text851">2</text>
<path style="fill:#11ff32; opacity: 0.6" d="m 80.840839,55.70118 a 3.8540533,3.9690995 0 0 1 -3.854053,3.969099 3.8540533,3.9690995 0 0 1 -3.854053,-3.969099 3.8540533,3.9690995 0 0 1 3.854053,-3.9691 3.8540533,3.9690995 0 0 1 3.854053,3.9691 z"/></g>
</g>

<g mask="url(#crossoverMask3)">
<g id="ball3">
	     <text
     xml:space="preserve"
     style="" class="ballText"
     x="75"
     y="57.6"
     id="text851">3</text>
<path style="fill:#123456; opacity: 0.6" d="m 80.840839,55.70118 a 3.8540533,3.9690995 0 0 1 -3.854053,3.969099 3.8540533,3.9690995 0 0 1 -3.854053,-3.969099 3.8540533,3.9690995 0 0 1 3.854053,-3.9691 3.8540533,3.9690995 0 0 1 3.854053,3.9691 z"/></g>
</g>

<g mask="url(#crossoverMask4)">
<g id="ball4">
	     <text
     xml:space="preserve"
     style="" class="ballText"
     x="75"
     y="57.6"
     id="text851">4</text>
<path style="fill:#ff43ff; opacity: 0.6" d="m 80.840839,55.70118 a 3.8540533,3.9690995 0 0 1 -3.854053,3.969099 3.8540533,3.9690995 0 0 1 -3.854053,-3.969099 3.8540533,3.9690995 0 0 1 3.854053,-3.9691 3.8540533,3.9690995 0 0 1 3.854053,3.9691 z"/>
</g>
</g>
	   <!-- pipe cover -->
<path id="pipeCover" style="fill:#1a2b3c" d="M 68.44934,2.5703992 V 75.373138 h 63.74414 V 2.5703992 Z M 99.87317,9.065189 c 6.20593,0.08361 11.86368,4.076661 15.03906,9.285157 3.23577,5.661451 4.79166,12.426445 3.87891,18.921875 -1.00289,7.6037 -7.06712,13.518532 -13.81055,16.544922 3.40257,3.64735 6.8155,7.283852 10.23633,10.914062 l -5.05469,4.806641 c -4.08234,-4.32871 -8.15352,-8.66825 -12.19922,-13.03125 -4.8604,1.42636 -9.88109,2.309464 -14.9375,2.615234 l -0.28125,-6.970703 c 3.34529,-0.21207 6.66895,-0.720295 9.9375,-1.458984 -1.85326,-2.23898 -3.34366,-4.758049 -4.56054,-7.392579 -3.02793,-6.91112 -5.14919,-14.745237 -3.39063,-22.273437 1.29715,-6.48429 7.21537,-11.781139 13.89453,-11.923828 0.41803,-0.02998 0.83432,-0.04268 1.24805,-0.03711 z m -0.8418,6.94336 c -7.04167,0.3141 -7.75189,7.515773 -7.65429,14.064453 1.09814,6.71045 3.73391,13.442514 8.59179,18.333984 3.4793,-1.43388 6.903,-3.340003 9.33008,-6.283203 3.63875,-4.21139 3.17951,-10.27137 1.75781,-15.27539 -1.26687,-5.548501 -5.95786,-10.990734 -12.02539,-10.839844 z" />
</svg>
              
            
!

CSS

              
                body
{
	font-family: arial, sans-serif;
}

h2
{
	font-size: 16px;
}

.ballText
{
	font-size: 6px;
}
              
            
!

JS

              
                gsap.registerPlugin(gsap);
gsap.registerPlugin(MotionPathPlugin);
var aniDuration;
for (  i = 1;  i < 5;  i++) 
 // send balls 1 - 4 around the motion path, and each crossover mask into position when the ball is halfway through its motion animation.
{
  aniDuration = 3 + Math.floor(Math.random() * 15); // Create a different animation duration for each ball
  gsap.set("#crossoverMaskHandler" + i, {
    x: 41, delay: aniDuration / 2
  });
  gsap.to("#ball" + i, {
    motionPath: {
      path: "#motionPath",
      autoRotate: true,
      alignOrigin: "50% 50%"
    },
    transformOrigin: "50% 50%",
    duration: aniDuration,
    ease: "none"
  });
}

              
            
!
999px

Console