Programming and Technology
RSS icon Home icon
  • jQuery Image Loader

    This is a quick and easy to use jquery plugin for asynchronously loading images on a page.

    Download:

      jquery.imageLoader-1.0.zip (774.9 KiB)

    Usage:

    1.  
    2. <html>
    3.   <head>
    4.     <script type="text/javascript" src="js/jquery.js"></script>
    5.     <script type="text/javascript" src="js/jquery.imageLoader.js"></script>
    6.     <script type="text/javascript">
    7.         jQuery(‘ul.dynamic-images li’).loadImages();
    8.     </script>
    9.   </head>
    10.   <body>
    11.         <ul class="dynamic-images">
    12.             <li src="img/image1.jpg"></li>
    13.             <li src="img/image2.jpg"></li>
    14.             <li src="img/image3.jpg"></li>
    15.         </ul>
    16.   </body>
    17. </html>
    18.  

    This is the simplest usage. The url of the image you want to load is assigned to the ’src’ attribute of the containing element. Each element will have an img tag dynamically injected, showing a placeholder image until the image has sucessfully loaded. On failure, a fallback image will be shown, these images are configurable.

    Callbacks:

    1.  
    2.   <ul class="dynamic-images">
    3.      <li src="img/image1.jpg" onload="img = arguments[0]; img.alt = ‘Test image 1′"></li>
    4.      <li src="img/image2.jpg" onload="img = arguments[0]; img.alt = ‘Test image 2′"></li>
    5.      <li src="img/image3.jpg" onload="img = arguments[0]; img.alt = ‘Test image 3′"></li>
    6.   </ul>
    7.  

    Callbacks can be defined per image.

    1.  
    2.     <script type="text/javascript">
    3.         jQuery(‘ul.dynamic-images li’).loadImages({
    4.            FailImage: ‘img/loadError.gif’
    5.         }, function(){
    6.            var img = jQuery(arguments[0]);
    7.            img.attr(‘width’, 100);
    8.            img.attr(‘height’, 100);
    9.         });
    10.     </script>
    11.  

    Callbacks can also be defined globally so they will be called for every image loaded.

    Options:

    A custom options hash can be passed to loadImages() to override the defaults.

    Option Default Value Description
    LoadingImage img/image-loader.gif Indicates the placeholder image to be shown while the real image is loading. It’s handy to show spinners and throbbers.
    FailImage img/image-loader-error.jpg The image to show if the real image cannot be loaded for whatever reason.
    • Share/Bookmark
Get Adobe Flash playerPlugin by wpburn.com wordpress themes