I'm trying to build an image gallery with php and lazyload. I have around 8000 images which shouldn't load at once.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<div class="gallery">
<?php
$dir = "img/";
$i = 0;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(is_file($dir . $file)){
echo "<img class='lazyload' data-src='img/$file' src='img/$file' width='auto' height='600px'>";
}
}
closedir($dh);
}
} ?>
<script src="https://afarkas.github.io/lazysizes/lazysizes.min.js"></script>
</div>
</body>
</html>
I can load every pic at once in the img folder but I am not able to load more while scrolling down. I don't want to load all images at once.