close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Multiple image rotate

Thread began 11/04/2009 8:11 am by edz_2392925 | Last modified 6/04/2013 6:36 am by edz_2392925 | 11546 views | 10 replies

Ray BorduinWebAssist

Here is a little script I wrote that will do the trick... It does more than rotate because it fades in and out, but you can always set the number of steps to 1 and the hide gap to 0 to get a straight image swap.
You can build up an array of the images and preload them like I do in the head, then use that array as the images to rotate.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<title>Untitled Document</title>
<script>
function fade(ImgID,ImgArray,StartAt, Steps, StartPos, Direction, Gap, ShowGap, HideGap){
Steps=(Steps<1 || Steps>100)?15:Math.round(Steps);
Gap=(Gap<1)?75:Math.round(Gap);
ShowGap=(ShowGap<1)?75:Math.round(ShowGap);
HideGap=(HideGap<1)?75:Math.round(HideGap);
if(StartAt==ImgArray.length){
StartAt=0;
}
var ImgObj = document.getElementById(ImgID);
ImgObj.src=ImgArray[StartAt];
m=Math.round(StartPos/Steps*100);
ImgObj.style.filter="alpha(opacity="+m+")";
ImgObj.style.MozOpacity=m/100;
ImgObj.style.Opacity=m/100;
StartPos+=(Direction=="in")?1:(-1);
if(StartPos==Steps+1){
StartPos-=2;
Direction="out";
setTimeout("fade('"+ImgID+"',Array('"+String(ImgArray).replace(/,/g,"','")+"'),"+StartAt+","+Steps+","+StartPos+",'"+Direction+"',"+Gap+","+ShowGap+","+HideGap+")",ShowGap);
}
else if(StartPos<=0){
StartPos =0;
Direction="in";
StartAt++;
setTimeout("fade('"+ImgID+"',Array('"+String(ImgArray).replace(/,/g,"','")+"'),"+StartAt+","+Steps+","+StartPos+",'"+Direction+"',"+Gap+","+ShowGap+","+HideGap+")",HideGap);
}
else {
setTimeout("fade('"+ImgID+"',Array('"+String(ImgArray).replace(/,/g,"','")+"'),"+StartAt+","+Steps+","+StartPos+",'"+Direction+"',"+Gap+","+ShowGap+","+HideGap+")",Gap);
}
}


// create image array
var img_array=new Array();
img_array[0]="image/page_00.jpg";
img_array[1]="image/page_01.jpg";
img_array[2]="image/page_02.jpg";
img_array[3]="image/page_03.jpg";
img_array[4]="image/page_04.jpg";
img_array[5]="image/page_05.jpg";

// preload images
var myimages = new Array();
for (x=0; x<img_array.length; x++){
myimages[x] = new Image();
myimages[x].src = img_array[x];
}


// set arguments
var imageID = "fader";
var steps=1; // How many steps would you like for fading?. Max is 100, min is 1.
var gap=75; // How long would you like the delay between each frame (in 1/1000 ths of a second)? Min is 1, max should be no more than 10000 (10 seconds).
var show_img_gap=3000; // How long would you like to show the image for before it starts to fade out again.
var hide_img_gap=0; // How long would you like to hide the image for before it starts to fade in again.
n=steps;
img_num=0;
fading="out";


var secondimageID = "secondfader";
secondimg_num=3;

</script>


</head>

<body onload="setTimeout('fade(imageID,img_array,img_num,steps,n,fading,gap,show_img_gap,hide_img_gap)',show_img_gap); setTimeout('fade(secondimageID,img_array,secondimg_num,steps,n,fading,gap,show_img_gap,hide_img_gap)',show_img_gap)">

<img id="fader" src="image/page_00.jpg" />


<img id="secondfader" src="image/page_02.jpg" />

</body>
</html>

Did this help? Tips are appreciated...

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...