Quantcast
Channel: Moishe BeshkinTag Archive » Moishe Beshkin
Viewing all articles
Browse latest Browse all 3

Dynamic image rotation

$
0
0

I consider two basic logics on the idea how to rotate images on the site.

  • Change image every time site is loaded. This logics can be realized with the simple php script.
    $results = array();
    $handler = opendir("banner");
    
    while ($file = readdir($handler)) {
            if ($file != "." && $file != "..") {
                       $results[] = $file;
            }
    }
    $banner_num = rand(0, count($results)-1);
    print '';
    

    In this example, we just place all needed pictures to directory banner/. Script reads the list of files from the directory and converts the list to an array. Then we randomly take index of array item and show it on the page.

  • Another way is to use simple jquery plugin for rotating images.
    Here is a wonderful simple jQuery script for rotating images on site.
    We can combine previous php example and this script.
    $results = array();
    $handler = opendir("banner");
    print '
    ';

    Then get needed files from here.
    Place the following code in

    
    
    
    
    

    At the end of file (before ) add the following code:

    
    Note: On IE7 there appear floating caption section even in case there is no caption set. To resolve this issue, add "height: '0px'" as parameter.
    


Viewing all articles
Browse latest Browse all 3

Trending Articles