Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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.

            
              <div id="atom">
  <div id="cloud">
    <div class="orbit">
		  <div class="path">
		    <div class="electron"></div>
		  </div>
	  </div>
		<div class="orbit">
		  <div class="path">
		    <div class="electron"></div>
		  </div>
		</div>
		<div class="orbit">
		  <div class="path">
		    <div class="electron"></div>
		  </div>
		</div>
	  <div class="orbit">
		  <div class="path">
		    <div class="electron"></div>
		  </div>
		</div>
	  <div id="nucleus"></div>
  </div>
</div>
            
          
!
            
              body { background:grey; overflow: hidden; }

#atom { position: absolute; top: 50%; left: 50%; width:300px; margin-left: -170px; margin-top: -146px; transition: all 1.5s; }

#cloud { width:300px; height:300px; perspective: 1000; position:relative; }

#nucleus { position:absolute; top:50%; left:50%; margin: -10px 0 0 -10px; width:25px; height:25px; border-radius:50%; background: #272727;}

.orbit { position:absolute; top:0; left:0; width:300px; height:300px; border-radius:300px; border:5px solid #ccc; transform-style: preserve-3d; transform: rotateX(80deg) rotateY(20deg);}

#cloud .orbit:nth-child(2) {transform: rotateX(80deg) rotateY(70deg)}
#cloud .orbit:nth-child(3) {transform: rotateX(80deg) rotateY(-20deg)}
#cloud .orbit:nth-child(4) {transform: rotateX(80deg) rotateY(-50deg)}

.path { width:300px; height:300px; position:relative; transform-style: preserve-3d; }

.electron { position: absolute; top:-5px; left:50%; margin-left:-5px; width:10px; height:10px; border-radius:10px; background:#ccc; }
            
          
!
            
              // Used to change the timings of all animations collectively
var timeline = new TimelineMax({}),
    electrons = document.querySelectorAll('.electron'),
    paths = document.querySelectorAll('.path'),
    startDuration = 2,
    delay = 0.5,

    // Gets the start of the last electron
    lastTweenStartTime = (electrons.length - 1) * delay,

    // Calculates when the last electron is done animating
    lastTweenEndTime = lastTweenStartTime + startDuration;

// Apply the GSAP animation to each electron and path
for (var i = 0; i < electrons.length; i++) {
    // Create the individual delay to create offset
    var myDelay = (i * delay);
    orbit(electrons[i], paths[i], myDelay);
}

// Slow the animation on mouseover
document.getElementById("atom").onmouseover = function () {
    TweenLite.to(timeline, startDuration, {
        timeScale: 0.1
    });
}
// Set the animation back to normal on mouse leave
document.getElementById("atom").onmouseout = function () {
    TweenLite.to(timeline, startDuration, {
        timeScale: 1
    });
}

// Repeat it when the last electron is done animating
timeline.add(repeat, lastTweenEndTime);

// Start ahead so there is no load time
timeline.seek(1.5);

// Give each electron and path their individual animations
function orbit(electron, path, delay) {
    var e = TweenMax.fromTo(electron, startDuration, 
    // Initial rotationX of 90 to make dots visible
    {   rotationX: '90' },
    // Keep the dots upright for the duration of the animation
    {
        rotationZ: '-360',
        rotationX: '90',
        ease: Linear.easeNone,
        repeat: 1
    });
    var p = TweenMax.to(path, startDuration, {
        rotationZ: '360',
        ease: Linear.easeNone,
        repeat: 1
    });
    // Add that animation to the total timeline
    timeline.add([e, p], delay);
}

// Repeat the animation
function repeat() {
    timeline.play(lastTweenStartTime);
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console