| 4 | * @returns {Promise} A promise that resolves when all the images are loaded. |
| 5 | */ |
| 6 | const preloadImages = (selector = 'img') => { |
| 7 | return new Promise((resolve) => { |
| 8 | // Use the imagesLoaded library to ensure all images are fully loaded. |
| 9 | // This is particularly useful for getting accurate dimensions, avoiding layout shifts, etc. |
| 10 | // `background: true` ensures background images are also loaded. |
| 11 | imagesLoaded(document.querySelectorAll(selector), {background: true}, resolve); |
| 12 | }); |
| 13 | }; |
| 14 | |
| 15 | /** |
| 16 | * Determines the direction from which the mouse entered an element. |