Line 137: | Line 137: | ||
</div> | </div> | ||
+ | <script type="text/javascript"> | ||
+ | (() => { | ||
+ | 'use strict'; | ||
+ | // Page is loaded | ||
+ | const objects = document.getElementsByClassName('low-res-parallax'); | ||
+ | Array.from(objects).map((item) => { | ||
+ | // Start loading image | ||
+ | const img = new Image(); | ||
+ | img.src = item.dataset.src; | ||
+ | // Once image is loaded replace the src of the HTML element | ||
+ | img.onload = () => { | ||
+ | item.classList.remove('low-res-parallax'); | ||
+ | return item.nodeName === 'IMG' ? | ||
+ | item.src = item.dataset.src : | ||
+ | item.style.backgroundImage = `url(${item.dataset.src})`; | ||
+ | }; | ||
+ | }); | ||
+ | })(); | ||
+ | |||
+ | </script> | ||
Revision as of 15:41, 14 October 2018