MCPcopy
hub / github.com/formkit/auto-animate / add

Function add

src/index.ts:601–634  ·  view source on GitHub ↗

* Adds the element with a transition. * @param el - Animates the element being added.

(el: Element)

Source from the content-addressed store, hash-verified

599 * @param el - Animates the element being added.
600 */
601function add(el: Element) {
602 if (NEW in el) delete (el as any)[NEW]
603 const newCoords = getCoords(el)
604 coords.set(el, newCoords)
605 const pluginOrOptions = getOptions(el)
606 if (!isEnabled(el)) return
607 if (isOffscreen(el)) {
608 // Skip entry animation if element is not visible in viewport
609 observePosition(el)
610 return
611 }
612 let animation: Animation
613 if (typeof pluginOrOptions !== "function") {
614 animation = (el as HTMLElement).animate(
615 [
616 { transform: "scale(.98)", opacity: 0 },
617 { transform: "scale(0.98)", opacity: 0, offset: 0.5 },
618 { transform: "scale(1)", opacity: 1 },
619 ],
620 {
621 duration: (pluginOrOptions as AutoAnimateOptions).duration * 1.5,
622 easing: "ease-in",
623 },
624 )
625 } else {
626 const [keyframes] = getPluginTuple(pluginOrOptions(el, "add", newCoords))
627 animation = new Animation(keyframes)
628 animation.play()
629 }
630 animations.set(el, animation)
631 animation.addEventListener("finish", updatePos.bind(null, el, false), {
632 once: true,
633 })
634}
635
636/**
637 * Clean up after removing an element from the dom.

Callers 1

animateFunction · 0.85

Calls 6

getCoordsFunction · 0.85
getOptionsFunction · 0.85
isEnabledFunction · 0.85
isOffscreenFunction · 0.85
observePositionFunction · 0.85
getPluginTupleFunction · 0.85

Tested by

no test coverage detected