Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with timer

    I need help in the time. i have a script that generated random images, but i need it that some how it does it my timer and not randomaly it should do it one after another. here is what i got Could some one please help.

    PHP Code:


    <html>

    <
    body>

    <
    script language="Javascript">
    <!--
    var 
    images = new Array()
    images[0] = 'glass.jpg'
    images[1] = 'ball.jpg'
    images[2] = '123.jpg'

    var images.length;
    var 
    buff = new Array()
    for (
    0ki++){
       
    buff[i] = new Image()
       
    buff[i].src images[i]
    }

    var 
    theImage Math.round(Math.random()*(k-1));

    function 
    imagesAppear(){
      
    document.write('<td height="65" valign="top" cellpadding="2">')
      
    document.write('<img src="'+images[theImage]+'">');
    }


    </script>


     <script type="text/javascript" language="javascript">
          imagesAppear();
        </script>

    </body>
    </html> 

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Location
    Chicago, IL
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <html>
    
    <head>
    <title>Image Swap</title>
    <script type="text/javascript">
    <!--
    var images=new Array()
    images[0]='glass.jpg'
    images[1]='ball.jpg'
    images[2]='123.jpg'
    
    var current_image=0;
    
    function imageSwap(){
    document.picture.src=images[current_image]
    document.picture.alt=images[current_image]
    current_image=current_image+1
    
    resetSwap=(current_image==images.length)?current_image=0:"";
    setTimeout("imageSwap()",2000);
    }
    //-->
    </script>
    </head>
    
    <body>
    <img name="picture" src="some_image.jpg" alt="some_image.jpg">
    <br></br>
    <input type="button" name="start" value="start" onclick="imageSwap();">
    </body>
    
    </html>
    Thats just an example, but you can change the '2000' in the setTimeout to whatever you want it. 2000 means the image will rotate every 2 seconds, 5000 would be 5 seconds, etc... It can handle more pictures, all you have to do is add them to the array.
    I'm only telling you how I would do it, not how its supposed to be done. ;)

  • #3
    Regular Coder
    Join Date
    Sep 2005
    Location
    Chicago, IL
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can also change the line 'current_image=current_image+1' to "current_image++" it means the same thing just a shorter way to do it.
    I'm only telling you how I would do it, not how its supposed to be done. ;)

  • #4
    New Coder
    Join Date
    Apr 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks i already found the answser, now i need a help in something else it is posted here http://www.codingforums.com/showthread.php?t=86077.

    It would be highly appciated if you could help.

    Thanks again,
    Kim

  • #5
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think some one should close this, besides you could always thank the people that helped you.

  • #6
    Regular Coder
    Join Date
    Sep 2005
    Location
    Chicago, IL
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I already replied to that thread.
    I'm only telling you how I would do it, not how its supposed to be done. ;)

  • #7
    New Coder
    Join Date
    Apr 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Jordans:

    if you are not looking i already thanked boxxer03. i did not quote but i was saying thanks to him. People like you create problem in the forums.

    thanks i already found the answser, now i need a help in something else it is posted here http://www.codingforums.com/showthread.php?t=86077.

    It would be highly appciated if you could help.

    Thanks again,
    Kim

    boxxer03 thanks for you help, but i was unable to find a way to realate a to the image on the internet. If you know anyother way or if you know that any way to do it by asp it will be higly appreciated.

    Thanks
    Kim

  • #8
    Regular Coder
    Join Date
    Sep 2005
    Location
    Chicago, IL
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can definetly do it. But it will be an excessive code because the problem you will have with relating pictures to dates is that if you have 5 pictures on the 6th day it needs to know to reset and since months stagger from 30-31 days and 28-29 (leap year) in February it creates a problem. So basically you would need a code that "knows" how many days are in each month and can break the month down and then assign a picture to each date and at the end of the month it also has to go from say image3 on the 31st of one month to image4 on the 1st of the next month instead of resetting for the month, but like I said it can be done, but it would be very time consuming and a large script. Your best bet would be to stick with using a timer to rotate the images periodically.
    I'm only telling you how I would do it, not how its supposed to be done. ;)

  • #9
    New Coder
    Join Date
    Apr 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Can't we use getDate(), getTime(), and all the other stuff like that.

    Thanks
    Kim

  • #10
    New Coder
    Join Date
    Apr 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This code does break the day and the month will this work?

    Code:
    theDate= new Date();
    months = new Array();
    days = new Array();
    months[1] ="jan.gif";
    months[2] ="feb.gif";
    months[3] ="mar.gif";
    months[4] ="apr.gif";
    months[5] ="may.gif";
    months[6] ="jun.gif";
    months[7] ="jul.gif";
    months[8] ="aug.gif";
    months[9] ="sep.gif";
    months[10] ="oct.gif";
    months[11] ="nov.gif";
    months[12] ="dec.gif";
    days[1] ="1st.gif";
    days[2] ="2nd.gif";
    days[3] ="3rd.gif";
    days[4] ="4th.gif";
    days[5] ="5th.gif";
    days[6] ="6th.gif";
    days[7] ="7th.gif";
    days[8] ="8th.gif";
    days[9] ="9th.gif";
    days[10] ="10th.gif";
    days[11] ="11th.gif";
    days[12] ="12th.gif";
    days[13] ="13th.gif";
    days[14] ="14th.gif";
    days[15] ="15th.gif";
    days[16] ="16th.gif";
    days[17] ="17th.gif";
    days[18] ="18th.gif";
    days[19] ="18th.gif";
    days[20] ="20th.gif";
    days[21] ="21st.gif";
    days[22] ="22nd.gif";
    days[23] ="23rd.gif";
    days[24] ="24th.gif";
    days[25] ="25th.gif";
    days[26] ="26th.gif";
    days[27] ="27th.gif";
    days[28] ="28th.gif";
    days[29] ="29th.gif";
    days[30] ="30th.gif";
    days[31] ="31st.gif";
    function printDate() {
    document.write('<img src="' + months[theDate.getMonth()+1] + '">'); // month
    document.write('<br>');
    document.write('<img src="' + days[theDate.getDate()] + '">'); // day
    }
    //  End -->
    </script>
    </HEAD>
    
    
    <BODY>
    
    
    <script>
    printDate();
    </script>

  • #11
    Regular Coder
    Join Date
    Sep 2005
    Location
    Chicago, IL
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    its decent but it depends on what your trying to do if your trying to change pictures by the day then you don't need the month code, because this code displays two images - one depending on the month and one dpeneing on the day. but if you wanted it to display the images by date then just remove the month crap and put in your image urls for the days and just repeat them (because i'm sure you don't have 31 different pictures to display, but who knows). The only thing is that like i said before on the 31st it'll display one image and then 1st of the next month instead of going tothe next image it will just reset itself.
    I'm only telling you how I would do it, not how its supposed to be done. ;)


  •  

    Posting Permissions

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