SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot virginiamonkeys's Avatar
    Join Date
    Jun 2003
    Location
    Stafford, Virginia, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I get this to preload only 1 image?

    I got a script that rotates my images, but I have almost 300 in stock and it is preloading all 300 once the script is started.

    How do I get it to preload one at a time, or nothing at all?

    Code:

    PHP Code:
    /*************************************************************************
      This code is from Dynamic Web Coding at http://www.dyn-web.com/
      Copyright 2001-3 by Sharon Paine 
      See Terms of Use at http://www.dyn-web.com/bus/terms.html
      regarding conditions under which you may use this code.
      This notice must be retained in the code as is!
    *************************************************************************/

    // image file names go in these arrays
    randImgObj.set1 = new Array("1.jpg""3.jpg""5.jpg""7.jpg""9.jpg""11.jpg""13.jpg""15.jpg""17.jpg""19.jpg""21.jpg""23.jpg"

    "25.jpg""27.jpg""29.jpg""31.jpg""33.jpg""35.jpg""37.jpg""39.jpg""41.jpg""43.jpg""45.jpg""47.jpg""49.jpg""51.jpg""53.jpg"

    "55.jpg""57.jpg""59.jpg""61.jpg""63.jpg""65.jpg""67.jpg""69.jpg""71.jpg""73.jpg""75.jpg""77.jpg""79.jpg""81.jpg""83.jpg"

    "85.jpg""87.jpg""89.jpg""91.jpg""93.jpg""95.jpg""97.jpg""99.jpg""101.jpg""103.jpg""105.jpg""107.jpg""109.jpg""111.jpg"

    "113.jpg""115.jpg""117.jpg""119.jpg""121.jpg""123.jpg""125.jpg""127.jpg""129.jpg""131.jpg""133.jpg""135.jpg""137.jpg"

    "139.jpg""141.jpg""143.jpg""145.jpg""147.jpg""149.jpg""151.jpg""153.jpg""155.jpg""157.jpg""159.jpg""161.jpg""163.jpg"

    "165.jpg""167.jpg""169.jpg""171.jpg""173.jpg""175.jpg""177.jpg""179.jpg""181.jpg""183.jpg""185.jpg""187.jpg""189.jpg"

    "191.jpg""193.jpg""195.jpg""197.jpg""199.jpg""201.jpg""203.jpg""205.jpg""207.jpg""209.jpg""211.jpg""213.jpg""215.jpg"

    "217.jpg""219.jpg""221.jpg""223.jpg""225.jpg""227.jpg""229.jpg""231.jpg""233.jpg""235.jpg""237.jpg""239.jpg""241.jpg"

    "243.jpg""245.jpg""247.jpg""249.jpg""251.jpg""253.jpg""255.jpg""257.jpg""259.jpg""261.jpg""263.jpg""265.jpg""267.jpg"

    "269.jpg""271.jpg""273.jpg""275.jpg""277.jpg""279.jpg""281.jpg""283.jpg""285.jpg""287.jpg""289.jpg""291.jpg""293.jpg");

    // for the second set of rotating images 
    randImgObj.set2 = new Array("2.jpg","4.jpg","6.jpg","8.jpg""10.jpg""12.jpg","14.jpg","16.jpg","18.jpg""20.jpg"

    "22.jpg","24.jpg","26.jpg","28.jpg""30.jpg""32.jpg","34.jpg","36.jpg","38.jpg""40.jpg""42.jpg","44.jpg","46.jpg","48.jpg""50.jpg"

    "52.jpg","54.jpg","56.jpg","58.jpg""60.jpg""62.jpg","64.jpg","66.jpg","68.jpg""70.jpg""72.jpg","74.jpg","76.jpg","78.jpg""80.jpg"

    "82.jpg","84.jpg","86.jpg","88.jpg""90.jpg""92.jpg","94.jpg","96.jpg","98.jpg""100.jpg""102.jpg","104.jpg","106.jpg","108.jpg""110.jpg"

    "112.jpg","114.jpg","116.jpg","118.jpg""120.jpg""122.jpg","124.jpg","126.jpg","128.jpg""130.jpg""132.jpg","134.jpg","136.jpg","138.jpg"

    "140.jpg""142.jpg","144.jpg","146.jpg","148.jpg""150.jpg""152.jpg","154.jpg","156.jpg","158.jpg""160.jpg"

    "162.jpg","164.jpg","166.jpg","168.jpg""170.jpg""172.jpg","174.jpg","176.jpg","178.jpg""180.jpg""182.jpg","184.jpg","186.jpg","188.jpg"

    "190.jpg""192.jpg","194.jpg","196.jpg","198.jpg""200.jpg""202.jpg","204.jpg","206.jpg","208.jpg""210.jpg"

    "212.jpg","214.jpg","216.jpg","218.jpg""220.jpg""222.jpg","224.jpg","226.jpg","228.jpg""230.jpg""232.jpg","234.jpg","236.jpg","238.jpg"

    "240.jpg""242.jpg","244.jpg","246.jpg","248.jpg""250.jpg""252.jpg","254.jpg","256.jpg","258.jpg""260.jpg"

    "262.jpg","264.jpg","266.jpg","268.jpg""270.jpg""272.jpg","274.jpg","276.jpg","278.jpg""280.jpg""282.jpg","284.jpg","286.jpg","288.jpg"

    "290.jpg""292.jpg","294.jpg");


    // If all the images you wish to display are in the same location, you can specify the path here 
    randImgObj.imagesPath "/images/160x170/";

    // No need to edit code below this line 
    /////////////////////////////////////////////////////////////////////
    Array.prototype.shuffle = function() { 
      var 
    itempi1i2;
      for (
    i=0i<this.lengthi++) { 
        
    i1 Math.floorMath.random() * this.length );
        
    i2 Math.floorMath.random() * this.length );
        
    temp this[i1];
        
    this[i1] = this[i2];
        
    this[i2] = temp;
      }
    }

    randImgObjs = []; // holds all random rotating image objects defined
    // constructor 
    function randImgObj(s) {
      
    this.speed=sthis.ctr=0this.timer=0;  
      
    this.index randImgObjs.lengthrandImgObjs[this.index] = this;
      
    this.animString "randImgObjs[" this.index "]";
    }

    randImgObj.prototype = {
      
    addImages: function(ar) { // preloads images
        
    this.imgObj.imgs = [];
        for (var 
    i=0ar[i]; i++) {
          
    this.imgObj.imgs[i] = new Image();
          
    this.imgObj.imgs[i].src randImgObj.imagesPath ar[i];
        }
      },

      
    rotate: function() { // controls rotation
        
    var ctr Math.floorMath.random() * this.imgObj.imgs.length );
        if (
    ctr == this.ctrctr = (ctr 0)? --ctr: ++ctr;
        
    this.ctr ctr;
        if ( 
    typeof this.imgObj.filters != "undefined" ) {
               
    this.imgObj.style.filter 'blendTrans(duration=1)';
          if (
    this.imgObj.filters.blendTransthis.imgObj.filters.blendTrans.Apply();
        }
        
    this.imgObj.src this.imgObj.imgs[this.ctr].src;
        if ( 
    typeof this.imgObj.filters != "undefined" && this.imgObj.filters.blendTrans )
          
    this.imgObj.filters.blendTrans.Play();    
      }
    }

    // sets up rotation for all defined randImgObjs
    randImgObj.start = function() {
      for (var 
    i=0i<randImgObjs.lengthi++) 
        
    randImgObjs[i].timer setInterval(randImgObjs[i].animString ".rotate()"randImgObjs[i].speed);                     
    }

    randImgObj.setUpImg = function(imgArspwh) {
      var 
    rotatorimgimgStr "";
      
    rotator = new randImgObj(sp);
      
    randImgObjs[randImgObjs.length-1].imgAr imgAr;
      
    imgAr.shuffle();
      
    img imgArMath.floorMath.random() * imgAr.length ) ]; 
      
    imgStr += '<img src="' randImgObj.imagesPath img '" alt="" ';
      
    imgStr += 'name="img' + (randImgObjs.length-1) + '" width="' '" height="' '">';
      
    document.write(imgStr); 
    }

    function 
    initRandRotation() {
      for (var 
    i=0randImgObjs[i]; i++) {
        var 
    rotator randImgObjs[i];
        
    rotator.imgObj document.images["img" i]; // get reference to the image object
        
    rotator.addImages(rotator.imgAr);
        
    rotator.rotate();
      }
      
    randImgObj.start();  


  2. #2
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YOUCH! That is one MONSTER of a script! Without reading every line of it it looks to be an animated type rotator .... am I right?

    If it is the images really do need to be preloaded or this thing will be going back to the server constantly to get the next image and they will load VERY slow (depending on the timer on the js they may not load by the time the next image is started)

    What exactly are you trying to accomplish here .... maybe theres a better way to do it. I also cant see ANYONE trying to rotate 300 images in an ongoing basis.... I honestly dont think any client will sit on one page long enough to see 1/10 of them ..... so if you post what you're trying to do maybe we can put something together that is better suited to your needs without attempting to download the Magna Carta on every page.... I cant ven imagine what the load time on this page is ....... holy smokes!

  3. #3
    Non-Member Musicbox's Avatar
    Join Date
    Nov 2004
    Location
    india
    Posts
    1,331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    search on yahoo

  4. #4
    SitePoint Zealot virginiamonkeys's Avatar
    Join Date
    Jun 2003
    Location
    Stafford, Virginia, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heh heh... okay...

    I just wanted a page that looked different everytime a user views it. Never the same way twice.

    It is a random rotator and it fades out in IE Windows. It just strictly randomly rotates in Firefox.

    Even if I had the script pick 2 batches of 10 random images (out of 294) to preload and worked with those 20 pictures on a rotating basis, that would do. I don't really need (or want) it to rotate the 300, just in case people DO leave the page running on their machine and it actually does download 300 images after all.


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
  •