/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Need help with image rotations

hi, I need to modify the following code which randomly displays 5 arrays of images in one row. it works fine with just one array but with all of them it chokes. It should dipslay the first following: row of all first images, replaced by a row of all second images and so on

Thank you !

<html>
<head>
<SCRIPT language=JavaScript type=”text/javascript”>
<!–
// image file names go in these arrays

randomImgObj.set1 = new Array(“”image1.1.jpg”,”image2.1.jpg”,”image3.1.jpg”,”image4.1.jpg”,”image5.1.jpg”);

randomImgObj.set2 = new Array(“image1.2.jpg”,”image2.2.jpg”,”image3.2.jpg”,”image4.2.jpg”,”image5.2.jpg”);

randomImgObj.set3 = new Array(“image1.3.jpg”,”image2.3.jpg”,”image3.3.jpg”,”image4.3.jpg”,”image5.3.jpg”);

randomImgObj.set4 = new Array(“image1.4.jpg”,”image2.4.jpg”,”image3.4.jpg”,”image4.4.jpg”,”image5.4.jpg”);

randomImgObj.set5 = new Array(“image1.5.jpg”,”image2.5.jpg”,”image3.5.jpg”,”image4.5.jpg”,”image5.5.jpg”);

randomImgObj.imagesPath = “”;

randomImgObjs = []; // holds all random rotating image objects defined constructor

var q=5;

function randomImgObj(s) {
this.speed=s; this.ctr=0; this.timer=0;
this.index = randomImgObjs.length; randomImgObjs[this.index] = this;
this.animString = “randomImgObjs[” + this.index + “]”;
}

randomImgObj.prototype = {
addImages: function(ar) { // preloads images
this.imgObj.imgs = [];
for (var i=0; ar[i]; i++) {
this.imgObj.imgs[i] = new Image();
this.imgObj.imgs[i].src = randomImgObj.imagesPath + ar[i];
}
},

rotate: function() { // controls rotation

var ctr;

ctr = this.imgObj.imgs.length-q;

this.ctr = ctr;
if ( typeof this.imgObj.filters != “undefined” ) {
this.imgObj.style.filter = ‘blendTrans(duration=1)’;
if (this.imgObj.filters.blendTrans) this.imgObj.filters.blendTrans.Apply();
}
this.imgObj.src = this.imgObj.imgs[this.ctr].src;
if ( typeof this.imgObj.filters != “undefined” && this.imgObj.filters.blendTrans )

this.imgObj.filters.blendTrans.Play();

q–;

if (q==0) q=this.imgObj.imgs.length;

}
}

// sets up rotation for all defined randomImgObjs
randomImgObj.start = function() {
for (var i=0; i<randomImgObjs.length; i++)
randomImgObjs[i].timer = setInterval(randomImgObjs[i].animString + “.rotate()”, randomImgObjs[i].speed);
}

randomImgObj.setUpImg = function(imgAr, sp, w, h) {
var rotator, img, imgStr = “”;
rotator = new randomImgObj(sp);
randomImgObjs[randomImgObjs.length-1].imgAr = imgAr;
img = imgAr[0];
imgStr += ‘<img src=”‘ + randomImgObj.imagesPath + img + ‘” alt=”” ‘;
imgStr += ‘name=”img’ + (randomImgObjs.length-1) + ‘” width=”‘ + w + ‘” height=”‘ + h + ‘”>’;
document.write(imgStr);
}

function imgRandomRotate() {
for (var i=0; randomImgObjs[i]; i++) {
var rotator = randomImgObjs[i];
rotator.imgObj = document.images[“img” + i]; // get reference to the image object
rotator.addImages(rotator.imgAr);
rotator.rotate();
}
randomImgObj.start();
}
//–>

</SCRIPT>
</head>

<BODY onLoad=”imgRandomRotate()”>

<SCRIPT language=JavaScript type=”text/javascript”>
// images array, delay, width and height of images
randomImgObj.setUpImg(randomImgObj.set1, 1000, 125, 125);
// images array, delay, width and height of images
randomImgObj.setUpImg(randomImgObj.set2, 1000, 125, 125);
// images array, delay, width and height of images
randomImgObj.setUpImg(randomImgObj.set3, 1000, 125, 125);
// images array, delay, width and height of images
randomImgObj.setUpImg(randomImgObj.set4, 1000, 125, 125);
// images array, delay, width and height of images
randomImgObj.setUpImg(randomImgObj.set5, 1000, 125, 125);
</SCRIPT>
</BODY>
</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsAug 06.2006 — this may help

[CODE]<html>
<head>
</head>

<BODY onload="zxcOOPSlideShow('TstSS2','RAO',2000);zxcOOPSlideShow('TstSS1','RAO',2500,1);" >
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="200" align="center" valign="middle" >
<div id="TstSS1" style="position:relative;width:100px;height:50px;" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Two.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Three.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Four.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Five.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Six.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Seven.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Eight.gif" width="100" height="50" >
</div>
<input class="TxtArea" type="button" name="" value="Next" onclick="zxcSSImg('TstSS1',1)">
<input class="TxtArea" type="button" name="" value="Auto" onclick="zxcSSImg('TstSS1')">
<input class="TxtArea" type="button" name="" value="Last" onclick="zxcSSImg('TstSS1',-1)"><br>
</td>
<td width="200" align="center" valign="middle" >
<div id="TstSS2" style="position:relative;width:100px;height:50px;" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Two.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Three.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Four.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Five.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Six.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Seven.gif" width="100" height="50" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/Eight.gif" width="100" height="50" >
</div>
<input class="TxtArea" type="button" name="" value="Next" onclick="zxcSSImg('TstSS2',1)">
<input class="TxtArea" type="button" name="" value="Auto" onclick="zxcSSImg('TstSS2')">
<input class="TxtArea" type="button" name="" value="Last" onclick="zxcSSImg('TstSS2',-1)">
</td>
</tr>
</table>

<script language="JavaScript" type="text/javascript">
<!--
// Simple Slide Show OOP (06-Aug-2006)
// by Vic Phillips http://www.vicsjavascripts.org.uk

// A Simple Slide Show utilising Object Orientated Technics
// allow as many applications as required to have independent functionality.
// Images are defied in the HTML Code and may be optionally randomised.
// Controls allow the display of a specific, next, previous image
// or images automatically sequenced.



// ***** The HTML Code
//
// Each Slide Show is defined in the HTML Code
// e.g.
// <div id="TstSS1" style="position:relative;width:100px;height:50px;" >
// <img src="One.gif" width="100" height="50" >
// <img src="Two.gif" width="100" height="50" >
// <img src="Three.gif" width="100" height="50" >
// </div>
// The parent <DIV> must be assigned a unique ID name
// and must have a positional style of 'position:relative;' or 'position:absolute;'
// The images may have a style of 'position:absolute;', this will be forced during initialisation.



// ***** Initialisation
// Each Slide Show must be initialised from a <BODY> or window onload event
// e.g.
// <body onload="zxcOOPSlideShow('fred','',2000,2);">
// where
// parameter 0 = the unique ID name of the Slide Show parent node. (string)
// parameter 1 = the mode, 'A' = auto rotate on loading, 'R' = randomise images 'O' = opacity. (string '', 'A', 'R' or 'RA')
// parameter 2 = the auto rotate delay between images in milliSeconds(default 1000). (digits)
// parameter 3 = the start image, starting from 1(default 1). (digits)



// ***** The Controls
//
// The Slide Shows may be controlled by an event call to function 'zxcSSImg'
// e.g.
// <input type="button" name="" value="Next" onclick="zxcSSImg('TstSS1',1)">
// <input type="button" name="" value="Auto" onclick="zxcSSImg('TstSS1')">
// <input type="button" name="" value="Last" onclick="zxcSSImg('TstSS1',-1)"><br>
// <img src="One.gif" width="25" height="13" onclick="zxcSSImg('TstSS1',0,1)" >
// where:
// parameter 0 = the unique ID name of the Slide Show parent node. (string)
// parameter 1 = the mode 1 = next image, -1 = previous image, 0 = auto sequence. (digits)
// parameter 2 = (optional) over rides parameter 2, the image number to display. (omit or digits)

// ***** General
//
// All variable, function etc. names are prefixed with 'zxc' to minimise conflicts with other JavaScripts
// These character are easily changed to characters of choice using global find and replace.
//
// The Functional Code(about 2K) is best as an External JavaScript.
//
// Tested with IE6 and Mozilla FireFox
//


// **** Functional Code - NO NEED to Change

function zxcSSImg(zxcid,zxcd,zxcnu){
var zxcoop=window['zxcSS'+zxcid];
if (!window['zxcSS'+zxcid]){ return; }
clearTimeout(zxcoop.to);
if (zxcnu){ if (zxcnu<1||zxcnu>=zxcoop.imgary.length){ return; }; zxcoop.cnt=zxcnu-1; zxcoop.d=0; zxcoop.next(); }
else if (zxcd==1||zxcd==-1){ zxcoop.d=zxcd; zxcoop.next(); }
else if (!zxcnu) { zxcoop.auto(); }
document.Show.Show0.value=vic++;
}

function zxcOOPSlideShow(zxcid,zxcmd,zxcdly,zxcfirst){
if (window['zxcSS'+zxcid]){ return; }
window['zxcSS'+zxcid]=new zxcSSOOP(zxcid,zxcmd,zxcdly,zxcfirst);
}

function zxcSSOOP(zxcid,zxcmd,zxcdly,zxcfirst){
var zxcp=document.getElementById(zxcid);
var zxcimgs=zxcp.getElementsByTagName('IMG');
if (!zxcimgs){ return; }
this.imgary=[];
for (var zxc0=0;zxc0<zxcimgs.length;zxc0++){
zxcSSStyle(zxcimgs[zxc0],{position:'absolute',zIndex:'0',left:'0px',top:'0px'});
this.imgary.push([zxcimgs[zxc0],0]);
if (zxcmd.match('O')){ zxcOpacity(zxcimgs[zxc0],0); }
}
if (zxcmd.match('R')){ this.imgary=this.imgary.randomise(); }
this.ref='zxcSS'+zxcid;
window[this.ref]=this;
this.to=null
this.to1=null
this.dly=zxcdly||1000;
this.d=1;
this.cnt=zxcfirst||1;
this.cnt--;
this.lst=[zxcimgs[this.cnt],100];
this.lst[0].style.zIndex='1';
zxcOpacity(this.lst[0],100);
this.md=zxcmd;
if (zxcmd.match('A')){ this.auto(); }
}

zxcSSOOP.prototype.next=function(){
clearTimeout(this.to1);
this.cnt+=this.d;
if (this.cnt==this.imgary.length){ this.cnt=0; }
if (this.cnt<0){ this.cnt=this.imgary.length-1; }
this.lst[1]=100;
zxcOpacity(this.lst[0],100);
this.lst[0].style.zIndex='0';
this.imgary[this.cnt][1]=0;
this.imgary[this.cnt][0].style.zIndex='1';
if (this.md.match('O')){ this.fade(); }
else { this.lst=this.imgary[this.cnt]; }
this.d=this.d||1;
}

zxcSSOOP.prototype.fade=function(){
for (var zxc0=0;zxc0<this.imgary.length;zxc0++){
if (this.imgary[zxc0][0]!=this.imgary[this.cnt][0]&&this.imgary[zxc0][1]>0){
zxcOpacity(this.imgary[zxc0][0],this.imgary[zxc0][1]--);
}
}
zxcOpacity(this.imgary[this.cnt][0],this.imgary[this.cnt][1]++);
if (this.imgary[this.cnt][1]<100){ this.setTimeOut1('fade()',5); }
else { this.lst=this.imgary[this.cnt]; }
}

zxcSSOOP.prototype.auto=function(){
this.next();
this.setTimeOut('auto()',this.dly);
}

zxcSSOOP.prototype.setTimeOut=function(zxcf,zxcd){
this.to=setTimeout('window.'+this.ref+'.'+zxcf,zxcd);
}

zxcSSOOP.prototype.setTimeOut1=function(zxcf,zxcd){
this.to1=setTimeout('window.'+this.ref+'.'+zxcf,zxcd);
}


function zxcOpacity(zxcobj,zxcopc) {
if (zxcopc<0||zxcopc>100){ return; }
if (zxcobj.style.MozOpacity!=null){ zxcobj.style.MozOpacity=(zxcopc/100)-.001; }
else if (zxcobj.style.opacity!=null){ zxcobj.style.opacity=(zxcopc/100)-.001; }
else if (zxcobj.style.filter!=null){ zxcobj.style.filter = 'alpha(opacity='+zxcopc+')'; }
else if (zxcobj.KHTMLOpacity!=null){ zxcobj.KHTMLOpacity=(zxcopc/100)-.001; }
}


Array.prototype.randomise=function(){
this.cnt=0; this.ta=[];
while (this.cnt<this.length){ zxctmp=Math.floor(Math.random()*this.length-1)+1; if (!this.ta[zxctmp]){this.ta[zxctmp]=this[this.cnt]; this.cnt++; } }
return this.ta;
}

function zxcSSStyle(zxcele,zxcstyle){
for (key in zxcstyle){ zxcele.style[key]=zxcstyle[key]; }
}


//-->
</script>
</BODY>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@ildarspbauthorAug 06.2006 — Thanks a lot, Vic !!!

Your script does exactly what i need, i just had to remove the call to the random function

All best
×

Success!

Help @ildarspb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...