Results 1 to 3 of 3

Thread: HTML/Javascipt Slideshow

  1. #1
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HTML/Javascipt Slideshow

    Pretty simple, I'm trying to me a slide show for my website (face in, 2.5 seconds later, fade out and move to the next one). I have a problem, I have tried everything to try and get the code working but I don't have a clue what the problem is.

    Anyone tell me if you can spot any errors? I have managed to get the image to appear on my page but won't start the slide.

    <html>
    <body>

    <head>
    <script type="text/javascript">
    <!--
    var image1=new Image()
    image1.src="Images\double.jpg"
    var image2=new Image()
    image2.src="Images\family.jpg"
    var image3=new Image()
    image3.src="Images\room.jpg"
    //-->
    </script>
    </head>

    <body>
    <center><img src="Images\double.jpg" name="slide" width="500" height="456" /></center>
    <script>
    <!--
    //variable that will increment through the images
    var step=1
    function slideit(){
    //if browser does not support the image object, exit.
    if (!document.images)
    return
    document.images.slide.src=eval("image"+step+".src")
    if (step<3)
    step++
    else
    step=1
    //call function "slideit()" every 1.0 seconds
    setTimeout("slideit()",2500)
    }
    slideit()
    //-->
    </script>

    </body>
    </html>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    1. The page has 2 body tags, only one allowed per page.

    2. The paths to the images use the wrong slash (\), it should be (/):

      Code:
       <script type="text/javascript">
       <!--
       var image1=new Image()
       image1.src="Images\double.jpg"
       var image2=new Image()
       image2.src="Images\family.jpg"
       var image3=new Image()
       image3.src="Images\room.jpg"
       //-->
       </script>
       </head>
      
       <body>
       <center><img src="Images\double.jpg" name="slide" width="500" height="456" /></center>
      should be:

      Code:
       <script type="text/javascript">
       <!--
       var image1=new Image()
       image1.src="Images/double.jpg"
       var image2=new Image()
       image2.src="Images/family.jpg"
       var image3=new Image()
       image3.src="Images/room.jpg"
       //-->
       </script>
       </head>
      
       <body>
       <center><img src="Images/double.jpg" name="slide" width="500" height="456" /></center>

    3. There's nothing in there that would cause the images to fade in or out.


    4. The use of eval there isn't necessary and may even be causing an error, try:

      Code:
      document.images.slide.src = window['image' + step].src;
      instead.


    Number 2 is probably the most serious. There could be other issues like missing images or other things with the code that aren't immediately apparent from your post.

    If you want more help:

    Please post a link to a page on your site that contains the problematic code so we can check it out.


    Also, for a slideshow that does fade in and out, see:

    http://www.dynamicdrive.com/dynamici...nslideshow.htm

    There are many others.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I badly worded my request, sorry. What I mean't was I was trying to get the slide to work, not fade in/out. I changed the "\" to "/" on the image code and it fixed everything, I now have a working slideshow and can work on adding more images to it.

    Thank you very much for your help.

    James.

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
  •