Reproducing Medium loading image effect

Size
2,240 Kb
Views
14,168

How do I make an reproducing medium loading image effect?

This is an attempt to reproduce the image loading animation seen on Medium, for my post https://jmperezperez.com/medium-image-progressive-loading-placeholder/ where I write about how to load images in a progressive way.. What is a reproducing medium loading image effect? How do you make a reproducing medium loading image effect? This script and codes were developed by José Manuel Pérez on 12 January 2023, Thursday.

Reproducing Medium loading image effect Previews

Reproducing Medium loading image effect - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Reproducing Medium loading image effect</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="placeholder" data-large="https://cdn-images-1.medium.com/max/1800/1*sg-uLNm73whmdOgKlrQdZA.jpeg"> <img src="https://cdn-images-1.medium.com/freeze/max/27/1*sg-uLNm73whmdOgKlrQdZA.jpeg?q=20" class="img-small"> <div style="padding-bottom: 66.6%;"></div>
</div> <script src="js/index.js"></script>
</body>
</html>

Reproducing Medium loading image effect - Script Codes CSS Codes

.placeholder { background-color: #f6f6f6; background-size: cover; background-repeat: no-repeat; position: relative; overflow: hidden;
}
.placeholder img { position: absolute; opacity: 0; top: 0; left: 0; width: 100%; -webkit-transition: opacity 1s linear; transition: opacity 1s linear;
}
.placeholder img.loaded { opacity: 1;
}
.img-small { -webkit-filter: blur(50px); filter: blur(50px); /* this is needed so Safari keeps sharp edges */ -webkit-transform: scale(1); transform: scale(1);
}

Reproducing Medium loading image effect - Script Codes JS Codes

window.onload = function() { var placeholder = document.querySelector('.placeholder'), small = placeholder.querySelector('.img-small') // 1: load small image and show it var img = new Image(); img.src = small.src; img.onload = function () { small.classList.add('loaded'); }; // 2: load large image var imgLarge = new Image(); imgLarge.src = placeholder.dataset.large; imgLarge.onload = function () { imgLarge.classList.add('loaded'); }; placeholder.appendChild(imgLarge);
}
Reproducing Medium loading image effect - Script Codes
Reproducing Medium loading image effect - Script Codes
Home Page Home
Developer José Manuel Pérez
Username jmperez
Uploaded January 12, 2023
Rating 4.5
Size 2,240 Kb
Views 14,168
Do you need developer help for Reproducing Medium loading image effect?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

José Manuel Pérez (jmperez) Script Codes
Create amazing art & images with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!