Results 1 to 4 of 4

Thread: Alternating images

  1. #1

    Thread Starter
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655

    Thumbs up

    Not difficult:
    Code:
    <script language="javascript">
    //Set up a variable to hold the current image.
    var curImg
    
    function animate(tImg){
    //Check tImg to find out what the image is displayed
    if(tImg == "On.jpg"){
    
    //Set the currently displayed image
    	curImg = "Off.jpg"}
    else{
            curImg = "On.jpg"}
    //Set img1 to be the current image
    document.img1.src = curImg;
    //set a timer up, mine change about every second
    //1000 milliseconds = about 1 second.
    window.setTimeout("animate(curImg)", 1000);
    }
    
    </script>
    <!-- Tell the page to animate -->
    <body onLoad="animate('Off.jpg')">
    <img src="" name="img1">
    In addition the the above you may want to add some preloading code for the images. Let me know if you need anything else.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  2. #2
    Lively Member
    Join Date
    Feb 1999
    Location
    Leicester, UK
    Posts
    123
    Thanks for that - it worked fine.

    The images I want to swap are small gifs (<1k) so preloading is not an issue here.

    However, I am sure that it would be useful to know for future reference how to preload larger graphics files, so what is the code to do this please?

  3. #3

    Thread Starter
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655

    Wink

    Well here is a way I came up with that makes preloading lots of images a breeze:

    Code:
    <script language="JavaScript">
    //Pre Load Images
    //By Realistic Graphics
    var Img = new Array()
    var tPath = "img/jpg/comp/"
    
    function PreImg(){
    Img[0] = "about2.jpg"
    Img[1] = "advert2.jpg"
    Img[2] = "contact2.jpg"
    Img[3] = "service2.jpg"
    Img[4] = "soft2.jpg"
    Img[5] = "web2.jpg"
    
    for(i=0; i < Img.length; i++){
    var tImg
    tImg = "img" + i
    tImg = new Image()
    tImg.src = tPath + Img[i]
    }
    }
    </script>
    <body onLoad="PreImg()">
    Let me know if you need anything else.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  4. #4
    Lively Member
    Join Date
    Feb 1999
    Location
    Leicester, UK
    Posts
    123
    Thanks. It is now filed away in my "odds and sods" folder!!!

    Can't think of anything else I need at the moment. Thanks for your help.

Posting Permissions

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



Click Here to Expand Forum to Full Width