UNPKG

vevet

Version:

Vevet is a JavaScript library for creative development that simplifies crafting rich interactions like split text animations, carousels, marquees, preloading, and more.

16 lines (11 loc) 358 B
export function preloadImage(resource: HTMLImageElement, onLoad: () => void) { if (resource.complete) { onLoad(); return; } const image = new Image(); image.addEventListener('load', () => onLoad()); image.addEventListener('error', () => onLoad()); image.crossOrigin = 'anonymous'; image.src = resource.currentSrc || resource.src; }