SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Toronto, Canada
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Image Arrays, possible?

    Hi there,

    I currently have a script that displays the larger version of the thumbnail in another cell other than the existing thumbnail cell (sorry for the confusing explanation! )

    Rather than doing this:

    imgoneon = new Image();
    imgoneon.src = "portfolio/thumbs/pic_db_01.jpg";
    imgtwoon = new Image();
    imgtwoon.src = "portfolio/thumbs/pic_an_01.jpg";
    imgthreeon = new Image();
    imgthreeon.src = "portfolio/thumbs/pic_el_01.jpg";
    imgfouron = new Image();
    imgfouron.src = "portfolio/thumbs/pic_gr_01.jpg";
    imgfiveon = new Image();
    imgfiveon.src = "portfolio/thumbs/pic_lo_01.jpg";

    Is there any way possible with JavaScript to create an array of images so that I don't have to manually type in each image name (I know that I will have to change the images to have a uniform prefix, but I don't mind that)...

    Also, would I have to change anything in the actualy mouse-over command?

    Any help would be greatly appreciated!

    TIA,

    Frank
    ...Shakes


    "Whether you think you can, or you think you can't, you're right!"

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    <script type="text/javascript">

    directory 'portfolio/thumbs/'

    var = new Array();

    i[0] = 'pic_db_';
    i[1] = 'pic_an_';
    i[2] = 'pic_el_';
    i[3] = 'pic_gr_';
    i[4] = 'pic_lo_';

    var 
    = new Array();

    n[0] = 'imgoneon';
    n[1] = 'imgtwoon';
    n[2] = 'imgthreeon';
    n[3] = 'imgfouron';
    n[4] = 'imgfiveon';



    for (
    a=0b=n.length-1;a<=b;a++)
    {
        
    document.write (n[a] + ' = new Image();<br>\n');
        
    document.write (n[a] + '.src = \"' directory i[a] + '<br>\n');
    }
    </script> 
    there is a much better way using php if you know how to use php which reads each image from a directory and puts them into an array

    PHP Code:
    <?

    print "var url = new Array;\n";

    $d dir('images/');
    $i=0;

    while (
    false !== ($entry $d->read())) {
        if (
    $entry != '.' && $entry != '..' && !is_dir('images/'.$entry))
        {
            
    $size  GetImageSize ('images/' $entry);
            
    $file  basename ('images/' $entry);
            
    $fileS filesize ('images/' $entry);

            print     
    "url[$i]        = 'images/$entry';            \n";
            print 
    "imgSize[$i] = 'Width   = $size[0] & Height = $size[1]';  \n";
            
    $i=$i+1;
        
        }

    }
    $d->close();
    ?>
    this prints each link, which can be javascript using an array.
    Last edited by Andrew-J2000; Apr 8, 2002 at 23:08.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Toronto, Canada
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the info! I will put it to good use!

    I want to give the PHP method a try. I've picked up a few books on PHP (by Larry Ullman), and am seriously considering purchasing Kevin Yank's book as well.

    Thanks again!


    ...Frank
    ...Shakes


    "Whether you think you can, or you think you can't, you're right!"

  4. #4
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well it was either that or write out, about 1500 arrays, you can guess which i picked lol


Bookmarks

Posting Permissions

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