In relation to animations on the internet, builders have to measure the animation’s necessities with the best know-how — CSS or JavaScript. Many animations are manageable with CSS however JavaScript will at all times present extra management. With doc.getAnimations, nonetheless, you should use JavaScript to handle CSS animations!

The doc.getAnimations technique returns an array of CSSAnimation objects. CSSAnimation offers a number of details about the animation: playState, timeline, impact, and occasions like onfinish. You possibly can then modify these objects to regulate animations:

// Make all CSS animations on the web page twice as quick
doc.getAnimations().forEach((animation) => {
  animation.playbackRate *= 2;
});

// Cease all CSS animations on the web page
doc.getAnimations().forEach((animation) => {
  animation.cancel();
});

How may adjusting CSS animations on the fly be helpful to builders? Perhaps use the Battery API to cease all animations when the system battery is low. Probably to cease animations when the person has scrolled previous the animation itself.

I like the best way you should use JavaScript to change CSS animations. Builders used to wish to decide on between CSS and JavaScript — now we’ve the instruments to make them work collectively!

  • 9 More Mind-Blowing WebGL Demos
  • Vibration API

    Most of the new APIs supplied to us by browser distributors are extra focused towards the cell person than the desktop person.  A type of easy APIs the Vibration API.  The Vibration API permits builders to direct the system, utilizing JavaScript, to vibrate in…


By admin

Leave a Reply

Your email address will not be published. Required fields are marked *