Browser Native Lazy Loading for IMG Images with `loading="lazy"`: A Practical Guide
Browser Native Lazy Loading for IMG Images with `loading="lazy"`: A Practical Guide This article was published on Monday, September 30, 2019, at 00:20, categorized under HTML-related and JS examples. Read 98,851 times, 15 times today, with 31 comments. by zhangxinxu from https:/...
Code: Dispatching a CustomEvent
const event = new CustomEvent('show', {
detail: { message: payload, sentAt: new Date().toLocaleTimeString() }
});
window.dispatchEvent(event);
Result
Waiting for an event...
Code: Listening for the Event Payload
window.addEventListener('show', (event) => {
render(event.detail.message, event.detail.sentAt);
});
Event log
No events yet.