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

Function autoAnimate

src/index.ts:883–971  ·  view source on GitHub ↗
(
  el: HTMLElement,
  config: Partial<AutoAnimateOptions> | AutoAnimationPlugin = {},
)

Source from the content-addressed store, hash-verified

881 * @param options - An optional object of options.
882 */
883export default function autoAnimate(
884 el: HTMLElement,
885 config: Partial<AutoAnimateOptions> | AutoAnimationPlugin = {},
886): AnimationController {
887 if (supportedBrowser && resize) {
888 const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)")
889 const isDisabledDueToReduceMotion =
890 mediaQuery.matches &&
891 !isPlugin(config) &&
892 !(config as Partial<AutoAnimateOptions>).disrespectUserMotionPreference
893 if (!isDisabledDueToReduceMotion) {
894 enabled.add(el)
895 if (getComputedStyle(el).position === "static") {
896 Object.assign(el.style, { position: "relative" })
897 }
898 forEach(el, updatePos, poll, (element) => resize?.observe(element))
899 if (isPlugin(config)) {
900 options.set(el, config as AutoAnimationPlugin)
901 } else {
902 options.set(el, {
903 duration: 250,
904 easing: "ease-in-out",
905 ...(config as Partial<AutoAnimateOptions>),
906 })
907 }
908 const mo = new MutationObserver(handleMutations)
909 mo.observe(el, { childList: true })
910 mutationObservers.set(el, mo)
911 parents.add(el)
912 }
913 }
914 const controller: AnimationController = Object.freeze({
915 parent: el,
916 enable: () => {
917 enabled.add(el)
918 },
919 disable: () => {
920 enabled.delete(el)
921 // Cancel any in-flight animations and pending timers for immediate effect
922 forEach(el, (node) => {
923 const a = animations.get(node)
924 try {
925 a?.cancel()
926 } catch {}
927 animations.delete(node)
928 const d = debounces.get(node)
929 if (d) clearTimeout(d)
930 debounces.delete(node)
931 const i = intervals.get(node)
932 if (i) clearInterval(i)
933 intervals.delete(node)
934 })
935 },
936 isEnabled: () => enabled.has(el),
937 destroy: () => {
938 enabled.delete(el)
939 parents.delete(el)
940 options.delete(el)

Callers 11

index.tsFile · 0.85
useAutoAnimateFunction · 0.85
useAutoAnimateFunction · 0.85
constructorMethod · 0.85
createAutoAnimateFunction · 0.85
useAutoAnimateFunction · 0.85
mountedFunction · 0.85
useAutoAnimateFunction · 0.85
basic.tsFile · 0.85
DropdownFunction · 0.85

Calls 2

isPluginFunction · 0.85
forEachFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…