\n \n <\/body>\n<\/html><\/pre>\n\n\n\n

And if you’re building for ES6+, I highly recommend using esbuild for transpiling, bundling, and minifying. For ES5, I suggest using esbuild (with minify off), Typescript (with target of ES5), and terser; as of now, this is the fastest setup to transpile to ES5, it’s faster and more reliable than babel. See the Gulpfile from the demo for more details.<\/p>\n\n\n

Conclusion<\/h3>\n\n\n

@okikio\/animate is a wrapper around the Web Animation API (WAAPI) that allows you to use all the features you love from animejs and other animation libraries, in a small and concise package. So, what are your thoughts after reading about it? Is it something you think you’ll reach for when you need to craft complex animations? Or, even more important, is there something that would hold you back from using it? Leave a comment below or join the discussion on Github Discussions.<\/p>\n\n\n\n\n\n\n\n

This article originally appeared on dev.to, it also appeared on hackernoon.com and my blog blog.okikio.dev.<\/small>
Photo by Pankaj Patel on Unsplash.<\/small><\/p>"}

国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Inhaltsverzeichnis
This is the library I made with the WAAPI
The story behind @okikio/animate
Where @okikio/animate fits into this article
Now, let’s get started
Usage, examples and demos
Restrictions and limitations
Looking to the future
Polyfills
Conclusion
Heim Web-Frontend CSS-Tutorial Wie ich mit dem WAAPI eine Animationsbibliothek erstellt habe

Wie ich mit dem WAAPI eine Animationsbibliothek erstellt habe

Mar 23, 2025 am 09:25 AM

How I Used the WAAPI to Build an Animation Library

The Web Animations API lets us construct animations and control their playback with JavaScript. The API opens the browser’s animation engine to developers and was designed to underlie implementations of both CSS animations and transitions, leaving the door open to future animation effects. It is one of the most performant ways to animate on the Web, letting the browser make its own internal optimizations without hacks, coercion, or window.requestAnimationFrame().

With the Web Animations API, we can move interactive animations from stylesheets to JavaScript, separating presentation from behavior. We no longer need to rely on DOM-heavy techniques such as writing CSS properties and scoping classes onto elements to control playback direction. And unlike pure, declarative CSS, JavaScript also lets us dynamically set values from properties to durations. For building custom animation libraries and creating interactive animations, the Web Animations API might be the perfect tool for the job. Let’s see what it can do!

For the rest of this article, I will sometimes refer to the Web Animation API as WAAPI. When searching for resources on the Web Animation API, you might be led astray by searching “Web Animation API” so, to make it easy to find resources, I feel we should adopt the term WAAPI; tell me what you think in the comments below.

This is the library I made with the WAAPI

@okikio/animate is an animation library for the modern web. It was inspired by animateplus, and animejs; it is focused on performance and developer experience, and utilizes the Web Animation API to deliver butter-smooth animations at a small size, weighing in at ~5.79 KB (minified and gzipped).

The story behind @okikio/animate

In 2020, I decided to make a more efficient PJAX library, similar to Rezo Zero’s – Starting Blocks project, but with the ease of use of barbajs. I felt starting blocks was easier to extend with custom functionality, and could be made smoother, faster, and easier to use.

Note: if you don’t know what a PJAX library is I suggest checking out MoOx/pjax; in short, PJAX allows for smooth transitions between pages using fetch requests and switching out DOM Elements.

Over time my intent shifted, and I started noticing how often sites from awwwards.com used PJAX, but often butchered the natural experience of the site and browser?. Many of the sites looked cool at first glance, but the actual usage often told a different story?—?scrollbars were often overridden, prefetching was often too eager, and a lack of preparation for people without powerful internet connections, CPUs and/or GPUs. So, I decided to progressively enhance the library I was going to build. I started what I call the “native initiative” stored in the GitHub repo okikio/native; a means of introducing all the cool and modern features in a highly performant, compliant, and lightweight way.

For the native initiative I designed the PJAX library @okikio/native; while testing on an actual project, I ran into the Web Animation API, and realized there were no libraries that took advantage of it, so, I developed @okikio/animate, to create a browser compliant animation library. (Note: this was in 2020, around the same time use-web-animations by wellyshen was being developed. If you are using react and need some quick animate.css like effects, use-web-animations is a good fit.) At first, it was supposed to be simple wrapper but, little by little, I built on it and it’s now at 80% feature parity with more mature animation libraries.

Note: you can read more on the native initiative as well as the @okikio/native library on the Github repo okikio/native. Also, okikio/native, is a monorepo with @okikio/native and @okikio/animate being sub-packages within it.

Where @okikio/animate fits into this article

The Web Animation API is very open in design. It is functional on its own but it’s not the most developer-friendly or intuitive API, so I developed @okikio/animate to act as a wrapper around the WAAPI and introduce the features you know and love from other more mature animation libraries (with some new features included) to the high-performance nature of the Web Animation API. Give the project’s README a read for much more context.

Now, let’s get started

@okikio/animate creates animations by creating new instances of Animate (a class that acts as a wrapper around the Web Animation API).

import { Animate } from"@okikio/animate";

new Animate({
  target: [/* ... */],
  duration: 2000,
  // ... 
});

The Animate class receives a set of targets to animate, it then creates a list of WAAPI Animation instances, alongside a main animation (the main animation is a small Animation instance that is set to animate over a non-visible element, it exists as a way of tracking the progress of the animations of the various target elements), the Animate class then plays each target elements Animation instance, including the main animation, to create smooth animations.

The main animation is there to ensure accuracy in different browser vendor implementations of WAAPI. The main animation is stored in Animate.prototype.mainAnimation, while the target element’s Animation instances are stored in a WeakMap, with the key being its KeyframeEffect. You can access the animation for a specific target using the Animate.prototype.getAnimation(el).

You don‘t need to fully understand the prior sentences, but they will aid your understanding of what @okikio/animate does. If you want to learn more about how WAAPI works, check out MDN, or if you would like to learn more about the @okikio/animate library, I’d suggest checking out the okikio/native project on GitHub.

Usage, examples and demos

By default, creating a new instance of Animate is very annoying, so, I created the animate function, which creates new Animate instances every time it’s called.

import animate from "@okikio/animate";
// or
import { animate } from "@okikio/animate";

animate({ 
  target: [/* ... */],
  duration: 2000,
  // ... 
});

When using the @okikio/animate library to create animations you can do this:

import animate from "@okikio/animate";

// Do this if you installed it via the script tag: const { animate } = window.animate;

(async () => {
  let [options] = await animate({
    target: ".div",

    // Units are added automatically for transform CSS properties
    translateX: [0, 300],
    duration: 2000, // In milliseconds
    speed: 2,
  });

  console.log("The Animation is done...");
})();

You can also play with a demo with playback controls:

Try out Motion Path:

Try different types of Motion by changing the Animation Options:

I also created a complex demo page with polyfills:

View demo

You can find the source code for this demo in the animate.ts and animate.pug files in the GitHub repo. And, yes, the demo uses Pug, and is a fairly complex setup. I highly suggest looking at the README as a primer for getting started.

The native initiative uses Gitpod, so if you want to play with the demo, I recommend clicking the “Open in Gitpod” link since the entire environment is already set up for you?—?there’s nothing to configure.

You can also check out some more examples in this CodePen collection I put together. For the most part, you can port your code from animejs to @okikio/animate with few-to-no issues.

I should probably mention that @okikio/animate supports both the target and targets keywords for settings animation targets. @okikio/animate will merge both list of targets into one list and use Sets to remove any repeated targets. @okikio/animate supports functions as animation options, so you can use staggering similar to animejs. (Note: the order of arguments are different, read more in the “Animation Options & CSS Properties as Methods” section of the README file.)

Restrictions and limitations

@okikio/animate isn’t perfect; nothing really is, and seeing as the Web Animation API is a living standard constantly being improved, @okikio/animate itself still has lots of space to grow. That said, I am constantly trying to improve it and would love your input so please open a new issue, create a pull request or we can have a discussion over at the GitHub project.

The first limitation is that it doesn’t really have a built-in timeline. There are a few reasons for this:

  1. I ran out of time. I am still only a student and don’t have lots of time to develop all the projects I want to.
  2. I didn’t think a formal timeline was needed, as async/await programming was supported. Also, I added timelineOffset as an animation option, should anyone ever need to create something similar to the timeline in animejs.
  3. I wanted to make @okikio/animate as small as possible.
  4. With group effects and sequence effects coming soon, I thought it would be best to leave the package small until an actual need comes up. On that note, I highly suggest reading Daniel C. Wilson’s series on the WAAPI, particularly the fourth installment that covers group effects and sequence effects.

Another limitation of @okikio/animate is that it lacks support for custom easings, like spring, elastic, etc. But check out Jake Archibald’s proposal for an easing worklet. He discusses multiple standards that are currently in discussion. I prefer his proposal, as it’s the easiest to implement, not to mention the most elegant of the bunch. In the meanwhile, I’m taking inspiration from Kirill Vasiltsov article on Spring animations with WAAPI and I am planning to build something similar into the library.

The last limitation is that @okikio/animate only supports automatic units on transform functions e.g. translateX, translate, scale, skew, etc. This is no longer the case as of @okikio/[email?protected], but there are still some limitations on CSS properties that support color. Check the GitHub release for more detail.

For example:

animate({
  targets: [".div", document.querySelectorAll(".el")],

  // By default "px", will be applied
  translateX: 300,
  left: 500,
  margin: "56 70 8em 70%",

  // "deg" will be applied to rotate instead of px
  rotate: 120, 

  // No units will be auto applied
  color: "rgb(25, 25, 25)",
  "text-shadow": "25px 5px 15px rgb(25, 25, 25)"
});

Looking to the future

Some future features, like ScrollTimeline, are right around the corner. I don’t think anyone actually knows when it will release but since the ScrollTimeline in Chrome Canary 92, I think it’s safe to say the chances of a release in the near future look pretty good.

I built the timeline animation option into @okikio/animate to future-proof it. Here’s an example:

Thanks to Bramus for the demo inspiration! Also, you may need the Canary version of Chrome or need to turn on Experimental Web Platform features in Chrome Flags to view this demo. It seems to work just fine on Firefox, though, so… ?.

If you want to read more on the ScrollTimeline, Bramus wrote an excellent article on it. I would also suggest reading the Google Developers article on Animation Worklets.

My hope is to make the library smaller. It’s currently ~5.79 KB which seems high, at least to me. Normally, I would use a bundlephobia embed but that has trouble bundling the project, so if you want to verify the size, I suggest using bundle.js.org because it actually bundles the code locally on your browser. I specifically built it for checking the bundle size of @okikio/animate, but note it’s not as accurate as bundlephobia.

Polyfills

One of the earlier demos shows polyfills in action. You are going to need web-animations-next.min.js from web-animations-js to support timelines. Other modern features the KeyframeEffect constructor is required.

The polyfill uses JavaScript to test if the KeyframeEffect is supported and, if it isn’t, the polyfill loads and does its thing. Just avoid adding async/defer to the polyfill, or it will not work the way you expect. You’ll also want to polyfill Map, Set, and Promise.

<html>
  <head>
    <!-- Async -->
    <script src=",es2015,es2018,Array.prototype.includes,Map,Set,Promise" async></script>
    <!-- NO Async/Defer -->
    <script src="./js/webanimation-polyfill.min.js"></script>
  </head>
  <body>
    <!-- Content -->
  </body>
</html>

And if you’re building for ES6+, I highly recommend using esbuild for transpiling, bundling, and minifying. For ES5, I suggest using esbuild (with minify off), Typescript (with target of ES5), and terser; as of now, this is the fastest setup to transpile to ES5, it’s faster and more reliable than babel. See the Gulpfile from the demo for more details.

Conclusion

@okikio/animate is a wrapper around the Web Animation API (WAAPI) that allows you to use all the features you love from animejs and other animation libraries, in a small and concise package. So, what are your thoughts after reading about it? Is it something you think you’ll reach for when you need to craft complex animations? Or, even more important, is there something that would hold you back from using it? Leave a comment below or join the discussion on Github Discussions.

This article originally appeared on dev.to, it also appeared on hackernoon.com and my blog blog.okikio.dev.
Photo by Pankaj Patel on Unsplash.

Das obige ist der detaillierte Inhalt vonWie ich mit dem WAAPI eine Animationsbibliothek erstellt habe. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Erkl?rung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Hei?e KI -Werkzeuge

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Clothoff.io

Clothoff.io

KI-Kleiderentferner

Video Face Swap

Video Face Swap

Tauschen Sie Gesichter in jedem Video mühelos mit unserem v?llig kostenlosen KI-Gesichtstausch-Tool aus!

Hei?e Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Hei?e Themen

PHP-Tutorial
1502
276
CSS -Tutorial zum Erstellen von Ladespinner und Animationen CSS -Tutorial zum Erstellen von Ladespinner und Animationen Jul 07, 2025 am 12:07 AM

Es gibt drei M?glichkeiten, einen CSS -Laderotator zu erstellen: 1. Verwenden Sie den Basisrotator der Grenzen, um eine einfache Animation durch HTML und CSS zu erreichen. 2. Verwenden Sie einen benutzerdefinierten Rotator mit mehreren Punkten, um den Sprungeffekt durch verschiedene Verz?gerungszeiten zu erreichen. 3. Fügen Sie einen Rotator in die Taste hinzu und wechseln Sie den Klassen über JavaScript, um den Ladestatus anzuzeigen. Jeder Ansatz betont die Bedeutung von Entwurfsdetails wie Farbe, Gr??e, Zug?nglichkeit und Leistungsoptimierung, um die Benutzererfahrung zu verbessern.

Behandeln Sie Probleme und Pr?fixe von CSS -Browser -Kompatibilit?t und Pr?fixe Behandeln Sie Probleme und Pr?fixe von CSS -Browser -Kompatibilit?t und Pr?fixe Jul 07, 2025 am 01:44 AM

Um mit CSS -Browser -Kompatibilit?t und Pr?fixproblemen umzugehen, müssen Sie die Unterschiede im Browser -Support verstehen und Anbieterpr?fixe vernünftigerweise verwenden. 1. Verstehen Sie gemeinsame Probleme wie Flexbox und Grid -Unterstützung, Position: Sticky Invaly und Animationsleistung ist unterschiedlich. 2. überprüfen Sie den Best?tigungsunterstützungsstatus von Caniuse. 3. Verwenden Sie korrekt -webkit-, -moz-, -ms-, -o- und andere Herstellerpr?fixe; 4. Es wird empfohlen, Autoprefixer zu verwenden, um automatisch Pr?fixe hinzuzufügen. 5. Postcss installieren und Browserlist konfigurieren, um den Zielbrowser anzugeben. 6. automatisch die Kompatibilit?t w?hrend des Baus bew?ltigen; 7. Modernizr -Erkennungsmerkmale k?nnen für alte Projekte verwendet werden; 8. Keine Notwendigkeit, die Konsistenz aller Browser zu verfolgen,

Was ist der Unterschied zwischen Anzeige: Inline, Anzeige: Block und Anzeige: Inline-Block? Was ist der Unterschied zwischen Anzeige: Inline, Anzeige: Block und Anzeige: Inline-Block? Jul 11, 2025 am 03:25 AM

ThemaNDiffercesbetweenplay: Inline, Block, Andinline-Blockinhtml/CsSarelayoutBehavior, Spaceusage und Stylingcontrol.1.inlineelementsflowwithtext, Don'tstartonNewlines, Ignorewidth/HeighthThorchingstyhorching-/idelthorchorching/ardaldhordhortaliTalding/ardaldhordelthortex

Das Styling besuchte Links unterschiedlich mit CSS Das Styling besuchte Links unterschiedlich mit CSS Jul 11, 2025 am 03:26 AM

Durch das Festlegen des von Ihnen besuchten Links k?nnen Sie die Benutzererfahrung verbessern, insbesondere in inhaltsintensiven Websites, um den Benutzern dabei zu helfen, sich besser zu navigieren. 1. Verwenden Sie CSS: Besuchte Pseudoklasse, um den Stil des besuchten Links wie Farb?nderungen zu definieren. 2. Beachten Sie, dass der Browser nur eine ?nderung einiger Attribute aufgrund von Datenschutzbeschr?nkungen erm?glicht. 3. Die Farbauswahl sollte mit dem Gesamtstil koordiniert werden, um abrupte abrupt zu werden. 4. Das mobile Terminal zeigt diesen Effekt m?glicherweise nicht an. Es wird empfohlen, ihn mit anderen visuellen Eingabeaufforderungen wie Icon -Auxiliary -Logos zu kombinieren.

Erstellen von benutzerdefinierten Formen mit CSS-Clip-Pfad Erstellen von benutzerdefinierten Formen mit CSS-Clip-Pfad Jul 09, 2025 am 01:29 AM

Verwenden Sie das Clip-Pfad-Attribut von CSS, um Elemente in benutzerdefinierte Formen wie Dreiecke, kreisf?rmige Kerben, Polygone usw. zu erregen, ohne sich auf Bilder oder SVGs zu verlassen. Zu den Vorteilen geh?ren: 1.. Unterstützt eine Vielzahl von Grundformen wie Circle, Ellipse, Polygon usw.; 2. reagierende Anpassung und anpassbar an mobile Terminals; 3. Einfach zu animation und kann mit Hover oder JavaScript kombiniert werden, um dynamische Effekte zu erzielen. 4. Es wirkt sich nicht auf den Layoutfluss aus und erfüllt nur den Anzeigebereich. H?ufige Verwendungen sind z. B. kreisf?rmiger Clip-Pfad: Kreis (50pxatcenter) und Dreieck-Clip-Pfad: Polygon (50%0%, 100 0%, 0 0%). Beachten

Wie erstelle ich reaktionsschnelle Bilder mit CSS? Wie erstelle ich reaktionsschnelle Bilder mit CSS? Jul 15, 2025 am 01:10 AM

Um reaktionsschnelle Bilder mit CSS zu erstellen, kann es haupts?chlich durch die folgenden Methoden erreicht werden: 1. Verwenden Sie maximale Breite: 100% und H?he: Auto, damit das Bild an die Containerbreite anpasst und gleichzeitig den Anteil beibeh?lt. 2. Verwenden Sie die SRCSet- und Gr??enattribute von HTML, um die an verschiedenen Bildschirme angepassten Bildquellen intelligent zu laden. 3.. Verwenden Sie Objektfit und Objektposition, um die Bildaufbindung und Fokusanzeige zu steuern. Gemeinsam stellen diese Methoden sicher, dass die Bilder auf verschiedenen Ger?ten klar und wundersch?n pr?sentiert werden.

Entmystifizierende CSS -Einheiten: PX, EM, REM, VW, VH -Vergleiche Entmystifizierende CSS -Einheiten: PX, EM, REM, VW, VH -Vergleiche Jul 08, 2025 am 02:16 AM

Die Auswahl der CSS -Einheiten h?ngt von den Entwurfsanforderungen und den reaktionsschnellen Anforderungen ab. 1.PX wird für die feste Gr??e verwendet, geeignet für eine pr?zise Kontrolle, aber mangelnde Elastizit?t; 2.Em ist eine relative Einheit, die leicht durch den Einfluss des übergeordneten Elements verursacht wird, w?hrend REM basierend auf dem Wurzelelement stabiler ist und für die globale Skalierung geeignet ist. 3.VW/VH basiert auf der Ansichtsfenstergr??e, die für das reaktionsschnelle Design geeignet ist. Die Leistung unter extremen Bildschirmen sollte jedoch Aufmerksamkeit geschenkt werden. 4. Bei der Auswahl sollte es ermittelt werden, ob reaktionsschnelle Anpassungen, Elementhierarchiebeziehungen und Ansichtsfensterabh?ngigkeit festgelegt werden. Angemessener Gebrauch kann die Layoutflexibilit?t und -wartung verbessern.

Was sind gemeinsame Inkonsistenzen von CSS -Browser? Was sind gemeinsame Inkonsistenzen von CSS -Browser? Jul 26, 2025 am 07:04 AM

Verschiedene Browser weisen Unterschiede in der CSS -Analyse auf, was zu inkonsistenten Anzeigeeffekten führt, haupts?chlich die Differenzentscheidung, die Berechnung des Boxmodells, die Flexbox- und Raster -Layout -Unterstützung und das inkonsistente Verhalten bestimmter CSS -Attribute. 1. Die Standardstilverarbeitung ist inkonsistent. Die L?sung besteht darin, CSSReset oder Normalize.css zu verwenden, um den anf?nglichen Stil zu vereinen. 2. Die Box -Modellberechnung der alten Version von IE ist unterschiedlich. Es wird empfohlen, eine einheitliche Boxgr??e: Border-Box zu verwenden. 3. Flexbox und Grid führen in Kantenf?llen oder in alten Versionen unterschiedlich ab. Weitere Tests und verwenden Sie Autoprefixer; 4. Einige CSS -Attributverhalten sind inkonsistent. Caniuse muss konsultiert und herabgestuft werden.

See all articles