SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I recently put up a page (www.intertechcable.com) that has a random image generator when the nav buttons are moused over. I'm relatively knew to javascripting, but was able to band aid some code together that, while large in file size, is doing the job. The customer has no concerns about the file size which is rather large, but when a new window is opened the javascript tries to reload the images generating a ton of hits and bandwidth.

    Any suggestions would be greatly appreciated as I can anticipate our server getting a little picky about this bandwidth hog.

  2. #2
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    The code was a little convaluted for me to even look at. Instead, I'll just give an example of a random image. Here's what I'd do:

    Code:
    imageArray = new Array("images/image1.gif","image2.jpg","image3.gif");
    
    
    function randImage(image){
    ran=Math.floor(Math.random()*imageArray.length);
    document.images[image].src = imageArray[ran];
    }
    
    randImage('tv1');
    randImage('tv2');
    randImage('tv3');
    and you just do the array for your iamges and use that function, and it should work. There's no reason to load all the images.

    aDog

  3. #3
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    understandable. I figured there was a better way to invent the wheel. thanks aDog.


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
  •