...

View Full Version : Lazyload Images (without using replacement)



Mycroft
09-26-2012, 11:08 AM
Hello,

This is my third post on codingforums, I've found it to be a great resource that I hope to contribute more to as I actually learn.

I've been building this pet project website that gets a lot of images on page from uploads, and the script that I currently have isn't functional with applesini's lazyload.

This is how I get images uploaded. It isn't compatible with using a replacement image, because it HAS to display the data of the image in src, and not data-original or any other proxy. How would I go about getting the images (get) from the script to lazy load as the user scrolls down the page?

I know this is a lot to ask, but I've done quite a bit of seeking and I haven't found anything to resolve this. Doing individual divs doesn't seem to work either.

Thank you so much!


<?php

$dir = 'i/';
$file_display = array('jpg', 'jpeg', 'png', 'gif');

if (file_exists($dir) == false)
{
echo 'Directory \'', $dir, '\' not found!';
}
else
{
$dir_contents = scandir($dir);

$files = array();
$i = 0;
foreach ($dir_contents as $file)
{
$file_type = strtolower(end(explode('.', $file)));

if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true)
{
$files[filemtime($dir . $file) . $i] = $file; // make an array of the filenames, using the modified time as the key
$i++;
}

}

krsort($files); // sort by key in reverse order

foreach($files as $file) // output files
{
echo '<a target="_blank" href="', $dir, $file, '" alt="', $file,'"/><img class="paint paintsize" src="', $dir, $file, '" alt="', $file,'"/></a>';
}
}
?>

VIPStephan
09-26-2012, 04:36 PM
I’d say store the image paths in a JS array (using the PHP foreach loop to echo them) and load them as required.

Mycroft
09-26-2012, 11:05 PM
Id say store the image paths in a JS array (using the PHP foreach loop to echo them) and load them as required.

How would I specifically go about doing that? Sorry for the trouble.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum