Click to See Complete Forum and Search --> : Automatic 'Cartoon' webcam
SMcClure34
05-12-2003, 04:48 AM
For my website, I wish to create a 'pretend' webcam, which will access ready-made pictures at specific intervals.
(E.G.
Between 12.00 AM and 9.00 AM, Display Image 1
Between 9.00 AM and 11.00 AM, Display Image 2
Between 11.00 AM and 3.00 PM, Display Image 3
Between 3.00 PM and 8.00 PM, Display Image 4
Between 8.00 PM and 11.00 PM, Display Image 5
Between 11.00 PM and 12.00 AM, Display Image 1)
Is there anyway I can do this, and configure it for differnt number of images and differnt intervals?
Gollum
05-12-2003, 05:08 AM
<html>
<script language="Javascript">
function ShowImage()
{
var oImg = document.getElementById('TheImage');
var d = new Date();
if ( d < 9 ) oImg.src = "Image1.gif";
else if ( d < 11 ) oImg.src = "Image2.gif";
else etc...
}
</script>
<body onload="ShowImage();" >
<img id="TheImage" src="spacer.gif">
</body>
</html>
Note this will show images depending on the local time of the browser. For images based on server time you'll need to use ASP or some other active server system
Gollum
05-12-2003, 05:20 AM
Oops, I forgot...
If you also want your image to change automatically, you will want to add...
// schedule another go in an hour
window.setTimeout("ShowImage();", 3600000);
... to the end of the function
SMcClure34
05-12-2003, 05:49 AM
Okey dokey ;-) Being a dumbass at Javascript, I'm going to have to ask this. What does the 'd' stand for (I.E. (D < 11)), and do I have to insert anything into the BODY? Thanks again.
Gollum
05-12-2003, 05:59 AM
no prob...
the 'd' is just a variable name (look a couple of lines up where it says "var d = new Date();"
You can put any HTML you feel like in the body but you will need the bit that says '<img id="TheImage" src="spacer.gif">' as the script bit uses this to display your image. The "spacer.gif" bit is just some dummy image to use until you've worked out which real image to use.
SMcClure34
05-12-2003, 07:52 AM
Ok :) So right now, D is the systems date? Cool. Is there anyway I could compare this to the minute of the day?
(E.G. (Hour X 60) + Minute )
Like 7:00AM would be 420 and 12:15PM would be 735?
And how do I do 'in-between' in Javascript? Is it something like :
(30 < d < 60)
Gollum
05-12-2003, 09:20 AM
There's no "in-between" in Javascript. The syntax is similar to C/C++, so...
if ( (d > 9) && (d <= 11) ) alert("9 < d <= 11");