C# Tutorials and offshore development in India
Tutorials Resources Forum Reviews Communities Interview Jobs Projects Training Videos


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...


Birthday Greetings
Learn Windows 7: Top 10 Windows 7 Gadgets   Find information on the best Windows 7 Gadgets in this article. I will describe the top 10 desktop gadgets for Windows 7.



Resources » Code Snippets » Javascript »

Randomizing Your Slide Show using JavaScript


Posted Date: 20 Sep 2009    Resource Type: Code Snippets    Category: Javascript
Author: datta gunturuMember Level: Gold    
Rating: 1 out of 5Points: 8 (Rs 8)



Hello Friends,


Randomizing Your Slide Show


This task shows how to produce a randomized slide show. The slide show continues to display random images for the list of available images as long as the page is being displayed in the browser.

<head>
<script type="text/javascript">
var imageList = new Array;
imageList[0] = new Image;
imageList[0].src = “Blue hills.jpg”;
imageList[1] = new Image;
imageList[1].src = “Sunset.jpg”;
imageList[2] = new Image;
imageList[2].src = “Water lilies.jpg”;
imageList[3] = new Image;
imageList[3].src = “Winter.jpg”;
function slideShow(imageNumber) {
document.slideShow.src = imageList[imageNumber].src;
var imageChoice = Math.floor(Math.random() * imageList.length);
window.setTimeout(“slideShow(“ + imageChoice + “)”,3000);
}

</script>
</head>
<body onLoad=”slideShow(0)”>
<img src=”image1.jpg” width=100 name=”slideShow”>
</body>

----------------------------------------------

Description


1)In the function, display the image specified in imageNumber in the
place of the image named slideShow:

document.slideShow.src = imageList[imageNumber].src;

2)Create a variable named imageChoice, and assign it a random number
from 0 to the last index in the imageList array by using

Math.floor, Math.random and imageList.length:
var imageChoice = Math.floor(Math.random() * imageList.length);

3)Use the window.setTimeout method to schedule a call to the
slideShow function with the value of imageChoice passed as a
parameter. This will display the next random image in three seconds:

window.setTimeout(“slideShow(“ + imageChoice + “)”,3000);





Responses to the resource: "Randomizing Your Slide Show using JavaScript"

No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Randomizing Your Slide Show JavaScript  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Outputting the Date and Time in a Selected Time Zone
Previous Resource: Validating Credit Card Numbers Using JavaScript
Return to Resources
Post New Resource
Category: Javascript


Post resources and earn money!
 
More Resources



About Us    Contact Us    Privacy Policy    Terms Of Use