I'm working on a webpage that loads high-resolution images after low-res images are applied and set them to the initially loaded small low-res images. This is done to load smaller blurred images faster and replace them with high-res images, unblurred after they have been loaded completely.
I'm trying javascript to add this functionality but got stuck. Particularly because I'm new to this. This is what I wrote so far. Any help is appreciated. T
(function() {
let image = document.images //all low-res blurred images of class "image"
let big_image = document.getElementsByClassName("image")
function loadImage() {
for (let i = 0; i <= big_image.length; i++) {
big_image.onload = function() {
image[i].src = big_image[i].src
image[i].className = "noBlur" //set class to noblur from image to remove the blur filter
}
}
}
setTimeout(function() {
big_image[0].src = "mainPage/res/fireWatch.jpg" //actual high res image srcs
big_image[1].src = "mainPage/res/mountainMan.jpg"
big_image[2].src = "mainPage/res/pyramid.jpg"
big_image[3].src = "mainPage/res/valley.jpg"
big_image[4].src = "mainPage/res/valley.jpg"
big_image[5].src = "mainPage/res/valley.jpg"
}, 50)
document.addEventListener('DOMContentLoaded', loadImage, false);
}());