andrewsmithy
Mar 19 2005, 06:08 AM
JavaScript Slideshow TutorialI'm going to show you how to make a impressive JavaScript slideshow. First, you're probably asking: why would I want to make a slideshow in JavaScript? There are a number of reasons. First, you don't have to build a new HTML page for each picture. Secondly, the page will load much faster because the of the compactness of the page. Ok let's get started with this example. First we'll add a <script> tag in the <head> of our HTML document. In that script tag we will build the following: CODE first = 1; last = 4; current = 1; function nextPicture() { // Hide current picture object = document.getElementById('slide' + current); object.style.display = 'none'; // Show next picture, if last, loop back to front if (current == last) { current = 1; } else { current++ } object = document.getElementById('slide' + current); object.style.display = 'block'; }
function previousPicture() { // Hide current picture object = document.getElementById('slide' + current); object.style.display = 'none'; if (current == first) { current = last; } else { current--; } object = document.getElementById('slide' + current); object.style.display = 'block'; }
First, I want you to look at the variables. first describes the first picture id, which is 1; last defines the last picture, and current holds the index of the current picture. The function nextPicture() hides the currently displayed picture, and displays the next picture using CSS controls. The function previousPicture() is almost exactly the same as nextPicture() except that it travels back one picture. Notice that current variable holds the current picture index. We are going to make this page styled through CSS. Here is my CSS code. you can change this to whatever you want. Put this in the <style> tag of your <head> tag. CODE .slideShow { background-color: #ebebeb; text-align: center; margin-bottom: 10px; padding: 5px; } .slides { position: relative; z-index: 1; display: none; } .setTitle, .slideTitle { font-family: "Franklin Gothic Book", Arial, Helvitica, sans-serif; } .setTitle { color: #995a01; font-size: 14px; font-weight: bold; } .slideTitle { color: #666666; font-size: 12px; } .controls { position: relative; z-index: 10; } #slide1 { display: block; } img { border: outset 1px #999999; }
Ok, now we are going to put our pictures in our page. We do this through standard HTML. I'll explain this part after we go over the code. CODE <div class="slideShow"> <div class="setTitle">Jaguars Track and Field Photos</div> <div id="slide1" class="slides"> <div class="slideTitle">Picture 01</div> <img src="pic01.jpg" height="300" width="400" border="0" /> </div> <div id="slide2" class="slides"> <div class="slideTitle">Picture 02</div> <img src="pic02.jpg" height="300" width="400" border="0" /> </div> <div class="controls"> <a href="javascript:previousPicture()" style="margin: 10px;">« Previous</a> <a href="javascript:nextPicture()" style="margin: 10px;">Next »</a> </div> </div>
This code goes in the <body> tag. I just put two slides on here, but you can easily add more. Here is the format for adding more slides. You place another <div> inside of the <div class="slideShow"> like this: CODE <div id="slideShow"> ... <div id="slide10"> <div class="slideTitle">Your Slide Title</div> <img src="pic10.jpg" height="600" width="430" border="0" /> </div> .... </div>
Ok, when all of this is put together, you have a quite nice Javascript-enhanced slideshow! Here is the code for the whole page. Remember to edit the variable last to be the same as your last slide number. CODE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Slideshow</title> <script language="JavaScript" type="text/javascript"> //<!-- //<![CDATA[ first = 1; last = 4; current = 1; function nextPicture() { // Hide current picture object = document.getElementById('slide' + current); object.style.display = 'none'; // Show next picture, if last, loop back to front if (current == last) { current = 1; } else { current++ } object = document.getElementById('slide' + current); object.style.display = 'block'; }
function previousPicture() { // Hide current picture object = document.getElementById('slide' + current); object.style.display = 'none'; if (current == first) { current = last; } else { current--; } object = document.getElementById('slide' + current); object.style.display = 'block'; } //]]> // --> </script> <style type="text/css"> <!-- .slideShow { background-color: #ebebeb; text-align: center; margin-bottom: 10px; padding: 5px; } .slides { position: relative; z-index: 1; display: none; } .setTitle, .slideTitle { font-family: "Franklin Gothic Book", Arial, Helvitica, sans-serif; } .setTitle { color: #995a01; font-size: 14px; font-weight: bold; } .slideTitle { color: #666666; font-size: 12px; } .controls { position: relative; z-index: 10; } #slide1 { display: block; } img { border: outset 1px #999999; } --> </style> </head> <body> <div class="slideShow"> <div class="setTitle">Your Title</div> <div id="slide1" class="slides"> <div class="slideTitle">Picture 01</div> <img src="pic01.jpg" height="300" width="400" border="0" /> </div> <div id="slide2" class="slides"> <div class="slideTitle">Picture 02</div> <img src="pic02.jpg" height="300" width="400" border="0" /> </div> <div id="slide3" class="slides"> <div class="slideTitle">Picture 03</div> <img src="pic03.jpg" height="300" width="400" border="0" /> </div> <div id="slide4" class="slides"> <div class="slideTitle">Picture 04</div> <img src="pic04.jpg" height="300" width="400" border="0" /> </div> <div class="controls"> <a href="javascript:previousPicture()" style="margin: 10px;">« Previous</a> <a href="javascript:nextPicture()" style="margin: 10px;">Next »</a> </div> </div> </body> </html>
There you go! If you have any problems, suggestions, or questions please reply to this post. If you like this code, please rate me! Thanks
Comment/Reply (w/o sign-up)
FeedBacker
Dec 29 2007, 01:49 PM
adding backgroundimage slide show.
Javascript Slideshow Tutorial
What would be the coding of adding backgroundimage slide show in javascript? -shiv
Comment/Reply (w/o sign-up)
karlosvalencia
Jan 5 2008, 05:06 AM
This is actually pretty cool. Tested it and works like a charm. Is there any way in java to protect the pictures so they cant be downloaded using right-click once they're displayed?
Comment/Reply (w/o sign-up)
games4u
Apr 30 2008, 10:32 AM
QUOTE(FeedBacker @ Dec 29 2007, 07:19 PM)  adding backgroundimage slide show.
Javascript Slideshow Tutorial What would be the coding of adding backgroundimage slide show in javascript?
-shiv The easiest way of background image slideshow is by assigning different backgrounds to different <div> tags. So the following part of above code: HTML <div id="slideShow"> ... <div id="slide10"> Some Text Here... </div> .... </div> can be changed to: HTML <div id="slideShow"> ... <div id="slide10" style="background-image:url(bg_image_10.bmp)"> Some Text Here... </div> .... </div> The style attribute can be given for all <div> tags. And if needed the text in all <div> tags can be same - this creates a background changing effect. I hope that solved your problem 
Comment/Reply (w/o sign-up)
ultranet
Sep 26 2008, 05:03 AM
Where I can get the source code of this example?
Comment/Reply (w/o sign-up)
agdurrette
Oct 29 2008, 01:50 PM
Dooood Thats sooo cool love it thanks so much how can i make it auto-play/play thanks
Comment/Reply (w/o sign-up)
minimcmonkey
Nov 4 2008, 04:32 PM
QUOTE This is actually pretty cool. Tested it and works like a charm. Is there any way in java to protect the pictures so they cant be downloaded using right-click once they're displayed? No, there is absolutely no way to stop a persistent person from getting your images. you can disable the context menu, and call alerts on right click etc, but there are plenty of other ways of getting the image. I have seen people position transparencies over their images, so you download a blank image when you try and right click it to save it. Unfortunately, the browser needs the URL of the image to show it, for which reason, there is no way of protecting it.
Comment/Reply (w/o sign-up)
asdftheking
Nov 16 2008, 06:41 AM
QUOTE(agdurrette @ Oct 29 2008, 08:50 AM)  Dooood Thats sooo cool love it thanks so much
how can i make it auto-play/play
thanks As soon as I set this up the first thing I did was make it autoplay, it just makes sense. If you haven't already figured it out or given up, here's how it goes: add two elements: CODE function nextPicture() { // Hide current picture object = document.getElementById('slide' + current); object.style.display = 'none'; // Show next picture, if last, loop back to front if (current == last) { current = 1; } else { current++ } object = document.getElementById('slide' + current); object.style.display = 'block'; setTimeout(nextPicture, 2500); //NEW LINE in the end of nextPicture function } //a self repeating call at a delay of 2.5 secs //adjust the seconds to your liking
(the line which needs to be added should be 24.) then in line 79 change <body> to: (it will be 78 if you haven't already made the first change) CODE <body onload="setTimeout(nextPicture, 2500);">
I'm sure within a day or two I'll get bored with this and make the pictures fade in and out to black and/or white. I'll probably give a how to on that as well. Let me know if this works for you!
Comment/Reply (w/o sign-up)
(G)brian
Apr 22 2009, 01:01 PM
Start and STOP
Javascript Slideshow Tutorial
It is nice that the slide show will start playing when loaded but what if you want to stop it and use the forward and backwards buttons? How about a pause or stop button? Any ideas on code for that?
Thanks
-question by brian
Comment/Reply (w/o sign-up)
(G)Jim Hollomon
Apr 28 2009, 01:01 AM
Slide Show JavaScript with Text Controls
Javascript Slideshow Tutorial
I need a JavaScript slideshow class customizable for text controls
Instead of thumbnails. I know I have seen them before, but I can't seem
To find one now. Anybody know of a open-source script that would do
Something like this. The highlighted text and slide auto scrolls, but
Can be selected onMouseOver and clicking navigates to a specified URL. Is this something you have already coded or would be willing to quote?
-question by Jim Hollomon
Comment/Reply (w/o sign-up)
iGuest
Nov 5 2009, 02:16 PM
How to add a small icon photo spread
Javascript Slideshow Tutorial
This is great! I was curious, though, what it would take to add a miniature photo spreadsheet to one side of this slide show? I have several bunches of photos that I wanted to create a small spreadsheet of. When the user clicked one of the photos, an enlarged photo would appear to the right or left of this small spreadsheet. Is that possible?
Comment/Reply (w/o sign-up)
iGuest
Oct 8 2009, 03:27 PM
Multiple slideshows on one page
Javascript Slideshow Tutorial
First of all, thank you for doing this, it is extremely useful and straight forward, the best html java tutorial I've seen so far. Great Work. Is there anyway of including more Slideshows than one, though? When I try it, the second one browses the first one. And they have the same size?
Is there any solution to this
Thank you again
-reply by Martin Samuelson
Comment/Reply (w/o sign-up)
iGuest
Jul 16 2009, 11:16 PM
Javascript Slideshow Tutorial
Javascript Slideshow Tutorial
This works great and cool.
One thing I found that, when I check on the next button twice or thrice the speed of the next or back slide increases and increases it keeps increases the keeps increasing.I have no control on the slide show.Is there a way to put pause or play button and how.
Thanks shan
-reply by Java learner
Comment/Reply (w/o sign-up)
iGuest
Jul 14 2009, 07:01 PM
Brilliant
Javascript Slideshow Tutorial
Thank you so much-this is totally brilliant and thanks for the auto-play version.I don't really know Java so thanks for explaining it piece by piece and them putting it together like I said Brilliant!
-reply by lordofsarcasm
Comment/Reply (w/o sign-up)
Similar Topics
Keywords : javascript, slideshow, make, slideshow, javascript
- Javascript Game
Free online dice game called "Greedy" (6)
Re-learning Javascript
(3) As rusty as I was with ActionScript when I started my new job, I'm even rustier at JavaScript.
I'm trying to generate a new div on a webpage, containing an html file that (at the moment)
holds only a simple .gif image. The page looks like this at the moment: function
creatediv(id, html, width, height, left, top) { var newdiv =
document.createElement('div'); newdiv.setAttribute('id', id); if (width)
{ newdiv.style.width = 300; } if (height) { newdiv.style.height = 250; }
if ((left || ....
Need Help With Javascript Drag And Drop Script
Having trouble with javascript drag and drop script. (3) hi, i have been trying to create a drag and drop menu for my new website, so that the navigation
menu can be moved around the site. This is the code i have: CODE Test run - Right click
menu function coordinates(event) { if (event.button==2) { var x=event.x; var y=event.y; }
document.getElementById("element").style.left=x; document.getElementById("element").style.top=y;
document.getElementById("element").style.visibility="visible"; var oldx=x; var oldy=y;
window.onmouseup=end(); window.onmousemove=coordinates(event); } function end() { } #el....
Adjusting Rows/cols Of Frames In Frameset Using Javascript Is Not Working In Firefox 3 Is Not Working
(4) I am not able to adjust frames length/width in a frameset using java script functions I am using
firefox 3. In below code changerows is not working for me. Where as same is working in IE6.
Please help me in resolving this issue. Note: here frameset1 is the name given to the FRAMESET.
CODE function changeRows() { parent.frameset1.rows="30%,70%" }function restoreRows() {
parent.frameset1.rows="50%,50%" } ....
Java Vs Javascript
(11) I thought they were completely different things. Surely javascript should be seperated from the rest....
Document.write & Noscript Questions (javascript)
(2) I am trying to use javascript to include a stylesheet depending on the user's resolution. The
HTML CODE " /> id) { initEditor(); } ?> if
(screen.width>=1050) { document.write(' '); } I'm running into two
problems. 1) The script doesn't seem to be writing anything. Fixed 2) The tags cause all
sorts of validation errors. From what I've read it seems as though the tag is not allowed
within the section -- is this correct? Could the same thing be accomplished just putting the
default style....
Flash And Javascript Interaction
swfobject js questions (1) I don't know if anyone on here is familiar with this script. You can check it out here .
Basically it's a script that is supposed to give you javascript control over a flash object. I
am using it for a flv player. My question is this. I would like to display the current file's
title in a span element on the page, but the function described to gather the information for the
current file doesn't seem to work for me. The function, as outlined on on this page looks
like this: CODE function getUpdate(typ,pr1,pr2,swf) { if(typ == 'state'....
Javascript Object Node Referencing Help
(5) I've got two buttons with an onclick event to set the hidden input field to a certain value then
continue submitting the form. I have more than one form on display on the page and I don't want
to use ids. Is there a way I can reference it from the button/button onclick event? the forms is
laid out like this echo" "; echo" "; echo" Edit "; echo" Delete "; echo" ";
So basically the idea is to fire off new_modify function and start referencing the hidden input type
with name of do and set it to the supplied argument then continue submitting t....
Capturing Username Of Computer
using javascript, is it possible? (3) I wondering if it is possible to try and make a java script to get the computer username and log it?
/huh.gif" style="vertical-align:middle" emoid=":huh:" border="0" alt="huh.gif" /> edit Topic
title ....
Is It Possible To Create A Web Based Mmo In Javascript?
And could there be free movement without reloading the page? (4) I would like to get some information before launching myself to the JS libraries. Is it possible to
load maps or images and with the press of a button "scroll" or move the image inside some kind of
window up, down, left or right? It would be like scrolling an image sideways, upwards or downwards.
I would also like to know if multiple connections can be made and lets say there was a user
standing in the location (127, 160) of the map, would there be the possibility of loading the image
of that player? Maybe with database connections and storing their information there?....
Javascript Error
Error "missing ) in parenthetical" with JSON statment (2) Hello! I'm trying to execute following code: CODE a=new Array();
a=eval("("+responseText+")"); for (prop in a) { e=document.getElementById(prop)
if (e) {e.innerHTML=a } and I recieve error in CODE a=eval("("+responseText+")");
what's wrong? responseText it's result from php2js() function. Apache 2.2.6/PHP5.2.5/MySQL
5.0.45....
Special Wii Javascript
New Javascript Objects for Wii (2) I found on Nintendo.com a while back some new javascript objects dealing with the Wii Remote. I
have decided to post a link to these new Javascript objects here. Wii javascript These new
Javascripts can detect whether or not a Wii Remote is enabled, the position of the pointer, and even
the tilt of the remote. It also has an object that determines the keypress of the Wii. These can be
very useful for Wii sites. Maybe have a menu load with AJAX when the remote is tilted. Add button
functionality such as when the A and B button are pressed, the form is submitted. Just....
I`m New To Javascript.
(5) Does anybody know where I can find a good site to teach me more than I already know. I know about
functions and how to set up alert scripts. I really wanna make a counter script.....
Javascript Events Not Working For Ie
(6) I just made this little html file and I used javascript to show which arrows you're pressing. It
just says the key code, but only for the arrows, so it will say "37, 38, 39, 40" if you're
pushing all the arrows. When you let go of the arrows, it won't show that value. It works
perfectly in Firefox, but I can't get it to run in Internet Explorer. The little notification
bar down in the bottom left of the window says there's an error, and it just sits there. All I
used was a function for onKeyDown and onKeyUp on the body, and every 10 milliseconds it sh....
Javascript - What's Your Browser?
(3) Here is the code that i picked up from a Javascript book that will tell you wether you are using
Firefox or Internet explorer. obviously the (navigator.appName ==" browser name ") can be changed
to different browsers. CODE What's your browser?
type="text/javascript"> if (navigator.appName =="Firefox") {
document.write("You are running a Firefox browser") } else { if
(navigator.appName == "Microsoft Internet Explorer") { document.write("You are runnin....
Web Applications: J2ee Or Javascript/css/html
(1) I'm currently programming web applications using AJAX/CSS/HTML and they're pretty
cross-browser. However when I heard of this language J2EE I had second thoughts. But I ran into GWT
(Google Web Toolkit) which compiles Java code to Javascript/HTML. With this said, my mind tells me
that Java developers desire to use Javascript/HTML languages to create web applications over Java.
So, which one should I start developing web applications in? Java? or Javascript....
How Do You Make A Javascript Calculator?
in a form (11) Hi, does anyone know how you would make a html form with javascript where it calculates number... i
will demonstrate below to make it more clear what i mean.. i want the form to have like three
buttons, MULTIPLY,DIVIDE. AND RESET.. and than i want it to have the fields where you type in the
numbers and it gives you the answer.. so its Field 1 * OR / Field 2 = Field 3 . does anyone know
how to make this work? i basiaclly want all the three functions to work with the same form. this is
a project grade in my web design class but i need help. Thanks....
Hiding <div> Boxes With Javascript
Javascript Help #1 (8) This is my first help post in this Java/JavaScript section. Can someone write/find me a piece of
code that will hide boxes? Preferred stuff: There is a bar that has the subtitle of the box
contents. A button on the right side of the bar shows and hides the div box. Contents are in a box
with a border and slides in and out of the bar smoothly and relatively quickly. Box MUST be
customizable using CSS internal/external stylesheets . Any help would be appreciated. All codes
will be tested and best code be selected.....
Javascript : No Right Click Script !@
This script will allow you to protect your source coad ! (12) This script will help you to protect your source code Add this to Section of your site !
HTML var message="Function Disabled!"; /////////////////////////////////// function
clickIE4(){ if (event.button==2){ alert(message); return false; } } function clickNS4(e){ if
(document.layers||document.getElementById&&!document.all){ if (e.which==2||e.which==3){
alert(message); return false; } } } if (document.layers){ document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4; } else if (document.all&&!document.getElementById){ document.onmoused....
What's The Relationship Between Javascript And Java
are they the same or different (7) I think most of you always confuse about java and javascript .So I make this topic to talk about it.
Javascript and Java ,they have the same first four letter. Java and Javascript is the two language
is very popular in the web world.Java is the general-purpose programming language that you can
create an application or an applet.Javascript is a script language that looks sort of like java;with
it you can do various nifty things in web pages.They are independent languages ,used for different
purposes.If you are interesting in creating a website you should learn how to w....
I'm Making My Own Javascript Only Rpg :d
earliest beta perhaps (7) Well I randomly decided to make an rpg. So far its all in javascript, and that's how I intend to
keep it. Eventually you will be able to save with a permanent cookie or by getting an encrypted
code. Right now you can only walk around and go to 2 maps. I have used preloading, and the maps load
extremely fast. But there is one problem, maybe you guys could help but I mostly just posted to tell
you guys something /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif"
/>. Well the problem is the character images load extremely slow and i know wh....
Adding Rows & Columns In Html Table Using Javascript
(4) I'm trying to create a website with a form that collects some user information to store in MySQL
database. However, I've a problem when I want to dynamically add new rows and columns in the
HTML table so that the user can add more information in the dynamically added textboxes. Here's
what I have: CODE
Quantity
unit(s)
....
One Click Copy And Paste To Clipboard
in simple Javascript (5) I've been search the web for few weeks to see if Java can do one click copy and paste function
to the clipboard and then I can just Ctrl-V the copied "texts." I initially got this idea when I
began to approve hosting application. Instead of writing the same message over and over again, I
decided to make me a page where I can simply copy the code to appropriate answers. And seems like my
laziness is the mother of inventions /laugh.gif' border='0' style='vertical-align:middle'
alt='laugh.gif' /> Instead of doing Ctrl-A, Ctrl-C then Ctrl-V to the post board I started....
Javascript Close Window
Javascript close window (19) Hi does anyone have a code to close the browser window. This code needs to be used to close an
actual full sized window, not a pop-up window.....
How Can I Resize The Web Browser?
using javascript (5) how can i resize the window with javascript, and how to center an element in the browser window?
thanks a lot!!! /blink.gif' border='0' style='vertical-align:middle' alt='blink.gif' />
Corrected title spelling. This is more appropriate in Programming section. Please, please make sure
that you post in the right section. ....
Javascript Window.open
Plz help me ,, thanks (5) When I try to run the following code in Internet Explorer I get an "Invalid argument" error but it
works fine on Firefox CODE window.open("users/ve_edit.php","edit
av","toolbar=no,location=no,directories=no,status=no,sc
rollbars=no,resizable=no,copyhistory=no,width=600, height=400"); plz help me /blink.gif'
border='0' style='vertical-align:middle' alt='blink.gif' /> ....
How To Insert Code With Javascript
How to insert into a div an amount of code (11) Hi, I have the next html page CODE function insertcode() { var code =" blablabal babala
babababab here comes header fadfafa anchor blalbababa " var myText =
document.createTextNode(code); document.getElementById("content").appendChild(myText); } -->
Insert Code This code insert the data as text. The html tags are not treated like markup.
I need to insert the code in a time. I mean i can not go tag per tag. (E.g.
document.createElement("p")... ) Is there any method to insert a pice of html code into a div and
keep it like code not like tex....
Java Is Not Javascript; Javascript Is Not Java
(2) Java, developed under the Sun Microsystems brand, is a full-fledged object-oriented programming
language. It can be used to create standalone applications and a special type of mini application,
called an applet. Applets are downloaded as separate files to your browser alongside an HTML
document, and provide an infinite variety of added functionality to the Web site you are visiting.
The displayed results of applets can appear to be embedded in an HTML page (e.g., the scrolling
banner message that is so common on Java-enhanced sites), but the Java code arrives as a separ....
Learning Javascript.
-->What I know and a question<-- (7) How hard is it to fully learn javascript? People say it is easy, however, it looks pretty
complicated! What do I know, you ask? I know how to make a button (that I describe in another
post) so that when you click it, it generates something at random. I have the script for it here:
var quotes = ; function getQuote() { var qs = document.getElementById("quote"); var quote =
quotes quotes ; alert(quote); } Describe button here. . . . . . Original script
copyright by ROADDHOGG....
Javascript resources?
ie, a book. (10) Hi, I'm trying to learn Javascript. The thing is, I don't have any reference material
around, so I'm gonna need to buy a book or something. Are there any which you would recommend? I
looked on some websites but there are literally hundreds of books of this kind. /blink.gif"
style="vertical-align:middle" emoid=":blink:" border="0" alt="blink.gif" /> (in answer to the
below, sorry sauron, didnt see that one)....
Looking for javascript, slideshow, make, slideshow, javascript
|
Searching Video's for javascript, slideshow, make, slideshow, javascript
See Also,
|
advertisement
|
|