| |
|
|
| |
| |
| |
| |
| function formatDate(date) { |
| const options = { year: 'numeric', month: 'long', day: 'numeric' }; |
| return new Date(date).toLocaleDateString('en-US', options); |
| } |
|
|
| |
| |
| |
| function debounce(func, wait) { |
| let timeout; |
| return function executedFunction(...args) { |
| const later = () => { |
| clearTimeout(timeout); |
| func(...args); |
| }; |
| clearTimeout(timeout); |
| timeout = setTimeout(later, wait); |
| }; |
| } |
|
|
| |
| |
| |
| function isInViewport(element) { |
| const rect = element.getBoundingClientRect(); |
| return ( |
| rect.top >= 0 && |
| rect.left >= 0 && |
| rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && |
| rect.right <= (window.innerWidth || document.documentElement.clientWidth) |
| ); |
| } |
|
|
| |
| |
| |
| function lazyLoadImages() { |
| const images = document.querySelectorAll('img[data-src]'); |
| images.forEach(img => { |
| if (isInViewport(img)) { |
| img.src = img.dataset.src; |
| img.removeAttribute('data-src'); |
| } |
| }); |
| } |
|
|
| |
|
|
|
|