In terms of animations on the net, builders have to measure the animation’s necessities with the suitable expertise — CSS or JavaScript. Many animations are manageable with CSS however JavaScript will at all times present extra management. With doc.getAnimations
, nevertheless, you should use JavaScript to handle CSS animations!
The doc.getAnimations
methodology returns an array of CSSAnimation
objects. CSSAnimation
supplies a bunch 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 might adjusting CSS animations on the fly be helpful to builders? Perhaps use the Battery API to cease all animations when the gadget battery is low. Presumably to cease animations when the person has scrolled previous the animation itself.
I like the best way you should use JavaScript to switch CSS animations. Builders used to wish to decide on between CSS and JavaScript — now we’ve the instruments to make them work collectively!
An Interview with Eric Meyer
Your early CSS books have been instrumental in pushing my love for entrance finish applied sciences. What was it about CSS that you just fell in love with and drove you to put in writing about it? At first blush, it was the simplicity of it as in comparison with the table-and-spacer…
MooTools Zoomer Plugin
I like to go searching the MooTools Forge. As somebody that creates a lot of plugins, I get lots of pleasure out of seeing what different builders are creating and presumably even how I might enhance them. One nice plugin I’ve discovered is…
AJAX For Evil: Spyjax with jQuery
Final 12 months I wrote a well-liked put up titled AJAX For Evil: Spyjax once I described a way referred to as “Spyjax”: Spyjax, as I do know it, is taking info from the person’s laptop to your personal use — particularly their searching habits. By utilizing CSS and JavaScript, I…