Here i will explain how to create a simple slideshow using javascript.
Our main function displaynext(shift) will receive the value of shift based on the navigational buttons clicked ( it will either +1 or -1 ) and it will receive the value of 0 at the time of page load. Inside the function first the value of present slide is changed after adding the value of shift with present slide value. Then by one if condition the value of slide is checked as it should be within the values of image array. The value should be between 0 and number of element in the array. Once the if condition is satisfied, by using the .src property of the image element of the document the image is displayed. In the next line we will download the next image to be shown at background to cache. This way the next image can be shown immediately without any time delay. Here is the code of displaynext function.
function displaynext(shift){
present_slide=present_slide + shift;
if(images.length > present_slide && present_slide >= 0){
document.images[''im''].src = images[present_slide];
var next_slide=present_slide + 1;
download(next_slide); // Download the next image
}
At the time of page load we will pass a value of 0 to displaynext function to display the first element of the image array. While displaying this first element since the present slide value will be 0 so the previous button will not be visible. Here is the complete code of the slide show page.
<html>
<head>
<title>(Type a title for your page here)</title>
<script language="JavaScript">
var present_slide=0;
var images = new Array("http://www.anyserver/image//2435.jpg",
"http://www.anyserver/image//2436.jpg",
"http://www.anyserver/image//2437.jpg",
"http://www.anyserver/image//2438.jpg",
"http://www.anyserver/image//2439.jpg",
"http://www.anyserver/image//2440.jpg",
"http://www.anyserver/image//2441.jpg",
"http://www.anyserver/image//2442.jpg");
objImage = new Image();
function download(img_src){
// preload the image file
objImage.src=images[img_src];
}
function displaynext(shift){
present_slide=present_slide + shift;
if(images.length > present_slide && present_slide >= 0){
document.images[''im''].src = images[present_slide];
var next_slide=present_slide + 1;
download(next_slide); // Download the next image
}
if(present_slide+1 >= images.length ){
document.f1.Next.style.visibility = "hidden";
present_slide=images.length-1;
}else{document.f1.Next.style.visibility = "visible";}
if(present_slide< =0 ){
document.f1.Prev.style.visibility = "hidden";
present_slide=0;
}else{
document.f1.Prev.style.visibility = "visible";}
}
</script>
</script></head>
<body onLoad="displaynext(0)">
<form name="f1? method=post action="">
<img name="im" /><br />
<input type="button" name="Prev" value=" << " onClick="displaynext(-1);"/>
<input type="button" name="Next" value=" />> " onClick="displaynext(1);">
</form>
</body>
</html>
Incoming search terms:
- Simple JavaScript Slideshow (116)
- php mysql slideshow tutorial (21)
- simple javascript slideshow tutorial (19)
- simple javascript slideshow with buttons (13)
- occasionality next image slideshow: comment added on: your comment (11)
- javascript simple slideshow (10)
- javascript simple slideshow tutorial (9)
- simple javascript slide show (8)
- egypt next image slideshow: comment added on: your comment (6)
- religion next image slideshow: comment added on: your comment (6)
- sent next image slideshow: comment added on: your comment (6)
- infection next image slideshow: comment added on: your comment (5)
- bird smasher 2 next image slideshow: comment added on: your comment (5)
- javascript image slideshow tutorial (4)
- next image slideshow comment added on your comments attention (4)
- javascript slideshow tutorials (4)
- jqgrid Script expired! (3)
- showed next image slideshow: comment added on: your comment (3)
- images previous next buttons using javascript (3)
- urging next image slideshow: comment added on: your comment (3)
- website slideshow easy tutorial (3)
- simple php mysql slideshow script (3)
- telecharger pageflip4 as3 (3)
- “Next Image” ”SlideShow:” ”Comment added on:” ”Your Comment” (3)
- simple slideshow javascript (3)
- simple javascript image slideshow (3)
- media next image slideshow: comment added on: your comment (3)
- eyes next image slideshow: comment added on: your comment (3)
- easy javascript slideshow (3)
- dermatology next image slideshow: comment added on: your comment (3)
- js Glider autoslide (3)
- page flip image slider using javascript (2)
- simple javascript slideshow html (2)
- javascript simple slide show with title (2)
- slideshow javascript tutorial mysql (2)
- pageflip4 copy & past the code below (2)
- javascript mysql Slideshow (2)
- javascript slide show tutorial (2)
- simple jscript slideshow (2)
- php javascript image slide show tutorial (2)
You will also be interested in ,
- Displaying or changing images each day
- Url rewriting examples using .htaccess
- How to install XAMPP
- Tag cloud using php, mysql and ajax with filter
- Display Tags in wordpress
- C sharp INTERVIEW QUESTIONS
- MD5 Function and Unique ID in php
- Get Method and Array Manipulation In Symfony
- Caching of images using javascript image object
- Recuva best file recovery software


This is what I was looking for a while! Appreciate for this.
Nice post,thanks for sharing..