<!-- If you can name your image files, and suffix each with an integer,
you can make it simpler: -->
<script>
function mondayImage(){
var n, now= new Date(), d= new Date(now.getFullYear(), 0, 0);
while(d.getDay()!== 1) d.setDate(d.getDate()+1);
n= Math.floor((now-d)/6.048e8);
document.getElementById('mondayimage').src= '/path/to/image.image'+n+'.jpg';
}
window.onload=mondayImage;
</script>
</head>
<body>
<img id='mondayimage' src="" alt="monday image">
So if you just want an image to rotate by the hour, put in "getHour" instead?
And if you want it to loop, add the comma at the end, right?
I'm just learning, but I want to make sure...
Thanks!
Which post # code are you asking about? There were two solutions.
What does your attempt look like?
It's always a good idea to try the modifications yourself so that you can learn from trying!
If they don't work, then at least we know what you are trying to do with YOUR code.
Probably easiest modification would be to get the week of the year
and do a divide by 2 to determine image or message to display.
pseudo code: (assumes using something similar to post #2)
var today = new Date();
var weekOfYear = today.getWeek();
var imgPointer = Math.floor(weekOfYear/2);
// use image pointer to point to element of image array to display
document.getElementById('WeeklyImage').src = imgList[imgPointer];
so if you want to rotate it by every 14 days you can just do % 14, that will give you number on what you can base rest of your logic
I read the original request that the image or message would change every 2 weeks, ie;
stable message for a 2 week period and then changed.
This assumption is based on post #8 and #10 where OP originally referred to post #2 code, I thought.
Your code seems to change every day for a 4 day, if you % 4,
or a 2 week period, if you % 14, and then repeats the images or messages.
What ever the OP wants is fine, but it would be nice to know what the exact requirements are as the request is somewhat vague!
Bookmarks