Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2012
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Lazyload Images (without using replacement)

    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 Code:
             <?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>';
        }
    }
    ?>
    Last edited by Mycroft; 09-26-2012 at 11:29 AM.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,638
    Thanks
    6
    Thanked 1,004 Times in 977 Posts
    I’d say store the image paths in a JS array (using the PHP foreach loop to echo them) and load them as required.

  • Users who have thanked VIPStephan for this post:

    Mycroft (10-04-2012)

  • #3
    New Coder
    Join Date
    Aug 2012
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by VIPStephan View Post
    I’d 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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •