SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need help with javascript cycle

    Hey guys I have been trying to do his for two days and can't get the code to work, it seems very easy to do but I can't get it. Does anyone know how to do this:

    Create a script that cycles through images, displaying each image for 5 seconds.

    So, what I want is a code that will how one picture for 5 seconds and then another one and another. I want to show 5 pictures like this does anyone know how to do this, because I can't figure it out at all. Can you also show me the HTML part where the body goes and all of that stuff because I think I have that stuff in the right place but can't seem to work it. Thank you very much.

  2. #2
    SitePoint Zealot chrisdpucci's Avatar
    Join Date
    Dec 2006
    Location
    On the internets
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry I'm still stumped, I tried and tried looking through those and doing examples but couldn't get it working, is there anyone on here that can maybe write out the code and show me where to put the links to the images in, because I swear I'm doing everything right and its not working.

    Thank you by the way that link did help a little.

  4. #4
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <head>
    <script type="text/javascript">
    var img=["image1","IMAGE2","ImAgE3","iMage4","image5!"]
    var c=0
    window.onload=function(){
    document.getElementById("d").innerHTML=img[c]
    setInterval(func,5000)}
    function func()
    {
    	c++
    	if(img.length>c)
    	{
    	document.getElementById("d").innerHTML=img[c]
    	}
    	else
    	{
    	c=0
    	document.getElementById("d").innerHTML=img[c]
    	}
    }
    </script>
    </head>
    <body>
    <div id="d"></div>
    </body>
    </html>

  5. #5
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it thank you guys I had to use a bunch of if else statements, it turned out to be pretty easy once I sat down for a while and tnoguht about it and did it.


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
  •