By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,479 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,479 IT Pros & Developers. It's quick & easy.

Image changer

P: n/a
Anyone recommend a good javascript image changer - preferably one that
does a random image with the ability to post a certain image on a day?

TTFN
Jim
Feb 22 '07 #1
Share this Question
Share on Google+
8 Replies

P: n/a
ASM
Barely Audible a écrit :
Anyone recommend a good javascript image changer - preferably one that
does a random image with the ability to post a certain image on a day?
or it is a random image
or it is the image of the day

or do you mean : random image except on sunday ?

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Feb 23 '07 #2

P: n/a
On Feb 22, 7:41 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
Barely Audible a écrit :
Anyone recommend a good javascript image changer - preferably one that
does a random image with the ability to post a certain image on a day?

or it is a random image
or it is the image of the day

or do you mean : random image except on sunday ?

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
It's quite simple. Please refer to a snippet here:
http://education.lcweblink.info

Choose Javascript, then Javascript Images

Feb 23 '07 #3

P: n/a
On Feb 22, 7:41 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote: Barely Audible a écrit :
>Anyone recommend a good javascript image changer - preferably one
that does a random image with the ability to post a certain image
on a day?
or it is a random image or it is the image of the day

or do you mean : random image except on sunday ?
No what I meant was a random image on a normal day but on say xmas day,
easter sunday etc or any other day I nominate a certain image would be
shown.

TTFN
Feb 25 '07 #4

P: n/a
ASM
Barely Audible a écrit :
>
>On Feb 22, 7:41 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote: Barely Audible a écrit :

or do you mean : random image except on sunday ?

No what I meant was a random image on a normal day but on say xmas day,
easter sunday etc or any other day I nominate a certain image would be
shown.
So you'l have
-1- an array for images to randomize
-2- an array with your special images
-3- a function to chose image relatively to the date

var randomImages = new Array();
var specialImages = new Array();

randomImages[0] = '0.jpg';
randomImages[1] = '1.jpg';
....
randomImages[12] = '12.jpg';

specialImages[0] = 'xmas.jpg'
specialImages[1] = 'grd_pa_birthday.jpg'
....
specialImages[56] = 'grd_ma_birthday.jpg'

function choseImage() {
ar pict = '';
var i = Math.random()*randomImages.length;
i = Math.floor(i*10);
var D = new Date();
var d = D.getDate(); if(d<10) d = '0'+d;
var m = D.getMonth()+1*1; if(m<10) m = '0'+m;
D = m+d+''; // D = month + day ( = 1225 for xmas)
var k = false;
switch(i) {
case '1225': k = 0; break;
case '0228': k = 1; break;
...
case '0508': k = 56; break;
}
if(k) pict = specialImages[k];
else pict = randomImages[i];
return pict;
}

onload = function() { document.images['day_img'].src = choseImage(); }
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Feb 25 '07 #5

P: n/a
On Feb 25, 11:07 am, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
var randomImages = new Array();
var specialImages = new Array();

randomImages[0] = '0.jpg';
randomImages[1] = '1.jpg';
...
randomImages[12] = '12.jpg';

specialImages[0] = 'xmas.jpg'
specialImages[1] = 'grd_pa_birthday.jpg'
...
specialImages[56] = 'grd_ma_birthday.jpg'
Or (nowadays more common):

var randomImages = ['0.jpg', '1.jpg', '2.jpg', /*...*/ '12.jpg'];

Or:

function randomImage(n) { return n+'.jpg'; }

var k = false;
switch(i) {
Do you mean "D" ?
case '1225': k = 0; break;
case '0228': k = 1; break;
...
case '0508': k = 56; break;
}
if(k) pict = specialImages[k];
So what happens if i == '1225'?
else pict = randomImages[i];
Maybe:

// For your normal images:
images = ['1.jpg', '2.jpg' /* ... */ ];

// Then, for your special images:
images['1225'] = 'xmas.jpg';
// etc.
// if you have less than 1000 rotating images and your dates always
have 4 digits, just index the array:

if (!(D in images)) D = i;
return images[D];

instead of the switch statement. You keep all your indexing in one
place that way, and don't have arbitrary 'go-between' indices.

Just some thoughts.

-David

Feb 25 '07 #6

P: n/a
In comp.lang.javascript message <45***********************@news.orange.f
r>, Sun, 25 Feb 2007 20:07:38, ASM <st*********************@wanadoo.fr.i
nvalidposted:
>
function choseImage() {
ar pict = '';
var i = Math.random()*randomImages.length;
i = Math.floor(i*10);
var D = new Date();
var d = D.getDate(); if(d<10) d = '0'+d;
var m = D.getMonth()+1*1; if(m<10) m = '0'+m;
D = m+d+''; // D = month + day ( = 1225 for xmas)
var k = false;
switch(i) {
case '1225': k = 0; break;
case '0228': k = 1; break;
...
case '0508': k = 56; break;
}
if(k) pict = specialImages[k];
else pict = randomImages[i];
return pict;
}
No point in choosing your random i until you know it's needed.

One can simplify - consider :

function Random(M) { return Math.floor(M*(Math.random()%1)) }

SI = []
SI[1225] = "Xmas.pic"
SI[229] = "Leap.pic"

RI = ["P0", "P1", "P2"]

D = new Date("2024/02/29")
i = (D.getMonth()+1)*100 + D.getDate()

pict = SI[i]

if (!pict) pict = RI[Random(RI.length)] // FAQ function

pict
--
(c) John Stockton, Surrey, UK. ??*@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.

Food expiry ambiguities: <URL:http://www.merlyn.demon.co.uk/date2k-3.htm#Food>
Feb 25 '07 #7

P: n/a
ASM
Dr J R Stockton a écrit :
In comp.lang.javascript message <45***********************@news.orange.f
r>, Sun, 25 Feb 2007 20:07:38, ASM <st*********************@wanadoo.fr.i
nvalidposted:
>function choseImage() {
(...)
No point in choosing your random i until you know it's needed.
Hello Doc,

Sure you're right
But ... you know ... and I allready said :
not too much difficult in first approach

Thanks for the shorter view point.

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Feb 26 '07 #8

P: n/a
ASM
David Golightly a écrit :
On Feb 25, 11:07 am, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
>var randomImages = new Array();
var specialImages = new Array();

randomImages[0] = '0.jpg';
randomImages[1] = '1.jpg';
...
randomImages[12] = '12.jpg';

specialImages[0] = 'xmas.jpg'
specialImages[1] = 'grd_pa_birthday.jpg'
...
specialImages[56] = 'grd_ma_birthday.jpg'

Or (nowadays more common):
var randomImages = ['0.jpg', '1.jpg', '2.jpg', /*...*/ '12.jpg'];
but perhaps less comprehensive ?
Or:

function randomImage(n) { return n+'.jpg'; }
no, because I suppose images could have "normal" names
(as those "special")
I wouln't have had to give them index of array as name :-(
>var k = false;
switch(i) {
Do you mean "D" ?
it could be :-/
> case '1225': k = 0; break;
case '0228': k = 1; break;
...
case '0508': k = 56; break;
}
if(k) pict = specialImages[k];

So what happens if i == '1225'?
Are you mad ? why not 125546789 images ?
Hope OP uses only 3 or 4 images :-)
(999 images could be enough no ?)
>else pict = randomImages[i];

Maybe:

// For your normal images:
images = ['1.jpg', '2.jpg' /* ... */ ];
yeap, but it is for lighted users.
// Then, for your special images:
images['1225'] = 'xmas.jpg';
// etc.
// if you have less than 1000 rotating images and your dates always
have 4 digits, just index the array:

if (!(D in images)) D = i;
return images[D];

instead of the switch statement. You keep all your indexing in one
place that way, and don't have arbitrary 'go-between' indices.

Just some thoughts.
not bad, not bad :-)
-David
I ask myself why anybody did answer to this question, if so much guys
know better how to do and how to teach it.

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Feb 26 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.