PDA

View Full Version : Banner Rotator on Timing



jandjweb
10-11-2007, 02:26 AM
Does anyone have a java script that I can put three pictures in it and have picture number one come up at 7:00 Am till 12:00 PM and then and then have picture number two come in at 12:01 PM till 6:30 PM and then have picture three come in at 6:31 PM till 6:59 AM the next day. Is this possiable?

jscheuer1
10-11-2007, 04:46 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<script type="text/javascript">
(function(){
var ims=['morning.jpg', 'afternoon.jpg', 'evening.jpg'];
var d=new Date(), h=d.getHours(), m=h*60+d.getMinutes();
var im_num=m>=7*60&&m<12*60? 0 : m>=12*60&&m<18*60+30? 1 : 2;
document.write('<img src="'+ims[im_num]+'">');
})();
</script>
</body>
</html>

jandjweb
10-11-2007, 06:34 PM
So is the above script already for me including the times that I have listed. And if I have to change the times how would I do so? Thanks for the script anyways.

boogyman
10-11-2007, 06:48 PM
So is the above script already for me including the times that I have listed. And if I have to change the times how would I do so? Thanks for the script anyways.

it looks like its all ready made.. the only thing you would need to change is the url to the image

var ims=['morning.jpg', 'afternoon.jpg', 'evening.jpg'];

jscheuer1
10-11-2007, 09:30 PM
That's right boogyman. To make it clearer (in the script):

7*60 is 7:00am

12*60 is 12:00 noon

18*60+30 is 6:30pm

jandjweb
10-13-2007, 03:38 AM
So how do I change the timing code if I have to change the times that
the pictures appear?

jscheuer1
10-13-2007, 07:21 AM
The timing is set here:


var im_num=m>=7*60&&m<12*60? 0 : m>=12*60&&m<18*60+30? 1 : 2;

In English - If the time is greater than or equal to 7:00am and less than 12:00 noon, show image #0, else if the time is greater than or equal to 12:00 noon and less than 6:30pm, show image #1, else show image #2.

That taken with my previous explanation of how the times are written:


7*60 is 7:00am

12*60 is 12:00 noon

18*60+30 is 6:30pm

You should be able to figure it out.