The easiest way I know how to do this is to use something like GSAP, which makes it easy to perform this function. You could potentially without a library like GSAP, but it would be incredibly difficult, take a lot of time, probably be nervous and work worse
However, when a GSAP type library is introduced, it becomes a little simpler. Hope the comments help a bit in explaining the code.
Essentially, I recreated the animation using GSAP, placed them on the timeline, and slowed down the timeline when it hung
Demo
// 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); }
Zach saucier
source share