www.webdeveloper.com
Results 1 to 5 of 5

Thread: display static image at night time

  1. #1
    Join Date
    Dec 2009
    Posts
    5

    display static image at night time

    I have the following script that cycles and updates images from a webcam throughout the day (sunrise to sundown). The updates stop for night time and i would like to create an "if" statement that when the images are no longer "refreshing" that a "default" image get posted until the AM when the webcam images are refreshed and cycled again.

    any ideas??

    here is the code as it stands today;

    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    var timeDelay = 30; // change delay time in seconds
    var d = new Date(); var ct=d.getTime();
    var Pix = new Array
    ("sfmi1.jpg"
    ,"sfmi2.jpg"
    ,"sfmi3.jpg"
    ,"sfmi4.jpg"
    ,"sfmi5.jpg"
    ,"sfmi6.jpg"
    ,"sfmi7.jpg"
    ,"sfmi8.jpg"
    );
    var howMany = Pix.length;
    timeDelay *= 1000;
    var PicCurrentNum = 0;
    var PicCurrent = new Image();
    PicCurrent.src = Pix[PicCurrentNum];


    function startPix() {
    setInterval("slideshow()", timeDelay);
    }
    function startPix() {
    setInterval("slideshow()", timeDelay);
    }
    function slideshow() {
    PicCurrentNum++;
    if (PicCurrentNum == howMany) {
    PicCurrentNum = 0;
    }
    PicCurrent.src = Pix[PicCurrentNum];
    ct++
    document["ChangingPix"].src = PicCurrent.src+'?'+ct;
    }
    // End -->
    </script>

  2. #2
    Join Date
    Oct 2006
    Posts
    939
    Hi sfmi,

    You already have var d = new Date();
    just under that line insert-
    alert( d.getUTCHours() +'\n'+ d.getUTCMinutes() )

    Can you work with that?
    Last edited by justinbarneskin; 12-14-2009 at 08:16 PM. Reason: UTC time

  3. #3
    Join Date
    Dec 2009
    Posts
    5
    It works (dispays Warning) but what I need is if the image has the same date/time stamp as previously posted then put up an static image (Webcam is not broacasting) until such time as the images start to be updated again and the refresh process starts up again.

  4. #4
    Join Date
    Oct 2006
    Posts
    939
    Your image paths are appended with ct. ct is milliseconds since some day in the year 1970 hence, the image paths will never reoccur in your script.

    If your webcam begins to broadcast at 6am your time, you need to make note of the alert then, and write an if statement to those UTC times. Also, you need to make note of the UTC time when your webcam stops broadcasting, be it when the sun goes down your time.

  5. #5
    Join Date
    Oct 2006
    Posts
    939
    The time scripts are moved into function slideshow() so as to check the time on each call. A new var is used intervalID to stop the call to slideshow() when the static image is used. You have a redundant slideshow() in your script above. No use to increment ct when ct is refreshed each time slideshow() is called. I randomly set your UTC times to play the slideshow between 2 and 20 hours UTC. You can adjust them. The code is similar if you need to set UTCMinutes also.
    HTML Code:
    <SCRIPT LANGUAGE="JavaScript">
    
    <!-- Begin
    
    var timeDelay = 30; // change delay time in seconds
    
    var intervalID;
    var Pix =["sfmi1.jpg","sfmi2.jpg","sfmi3.jpg","sfmi4.jpg","sfmi5.jpg","sfmi6.jpg","sfmi7.jpg","sfmi8.jpg"];
    
    var howMany = Pix.length;	timeDelay *= 1000;	var PicCurrentNum = 0;	var PicCurrent = new Image();
    
    PicCurrent.src = Pix[PicCurrentNum];
    
    function startPix() {
    	intervalID=setInterval("slideshow()", timeDelay);
    }
    function slideshow() {
    var d = new Date(); var ct=d.getTime();
    
     if(d.getUTCHours()>=2 && d.getUTCHours()<= 20){		
    		PicCurrentNum++;
    			if (PicCurrentNum == howMany) {	PicCurrentNum = 0;	}
    		PicCurrent.src = Pix[PicCurrentNum];
    		document["ChangingPix"].src = PicCurrent.src+'?'+ct;
    	}
     else{document["ChangingPix"].src ='myStaticImage.jpg';clearInterval(intervalID)}
    }
    // End -->
    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles