473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Image changer

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
8 1461
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Pierre Tremblay | last post by:
Hi! I am trying to display an image in my html document. The document contains the following line: <td class="Input"><img...
1
by: Spartanicus | last post by:
When using javascript to display a different image (based on the time of day) both IE and Moz re-execute the js when using the back function to return to a page with the js on it, this results in...
15
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
7
by: Spartanicus | last post by:
Afaik the use of a <noscriptelement is frowned upon nowadays. For a JS random image changer I tried to use a replacement by having the script change the HTML src attribute value of an img element....
7
by: Inny | last post by:
Hello again, Im using the code below in a child page (popup), the images are called from the parent page. When the changer is running, the child page goes white between images. I realise this is...
6
by: Inny | last post by:
Hello, Im using the background image change script below and I want to change each image with a transition, swipe, circle in, circleout etc randomly. Not sure how to make random transitions with...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.