Home Javascript Slideshow - Slideshow Sample 02
2010-08-01
Main Menu
external Links
Most Read
Support

If you like the products on these pages, your support is highly appreciated. Thank you very much!

Amount: 

JavaScript: Slideshow Sample02
Written by Andreas Berger   
Sunday, 01 March 2009 12:30

The second sample uses the possibility to work with one scriptfile and multiple slideshows. The assumption: Within a website we have multiple webpages with one slideshow each.

The file names "be_slide.html" and "be_slide.js" correspond with the file names in the sample that comes with the download of the script at JavaScript: slideshow. The following explanatory notes also refer to these files and show how to integrate the script from the HTML-page and set the parameters in the downloaded JavaScript be_slide.js.


be_slide.html - the webpage

As in sample 01 the first step is to integrate the script into the webpage, but this time we want to use one scriptfile with different slideshows. Therfor we have to link the script from the HEAD-section PLUS submit the settings we want to use for the slideshow on the page. First comes the script:
<script type="text/javascript" src="be_slide.js"></script>

The sample assumes, that the script is located in the same directory as the webpage, otherwise the path has to be adjusted

Now we add the settings for the slideshow and call it:

<script type="text/javascript" src="be_slide.js"></script>
<script type="text/javascript">
var pics1=new Array ('pics/pic01a.jpg', 'pics/pic01b.jpg', 'pics/pic01c.jpg');
var buttons1=new Array ('bwd.png', 'start.png', 'stop.png', 'fwd.png');
var be_0= new be_slideshow("0",pics1,"slideshow",400,300,"#ccc",1,1,20,"n","n","y",buttons1);
</script>
So, what have we done:
<script type="text/javascript">
    //this line opens a new SCRIPT-Tag
 
var pics1=new Array ('pics/pic01a.jpg', 'pics/pic01b.jpg', 'pics/pic01c.jpg');
    //In this array, set the pictures you want the slideshow to display.
    //They are uploaded to a subdirectory "pics" in this sample
 
var buttons1=new Array ('bwd.png', 'start.png', 'stop.png', 'fwd.png');
    //As we want to show control-elements, we add the 
    //settings for them. We may choose between textlinks
    //and buttons. Into this array therefor we insert either the text
    //to be displayed or the path to the images to be used.
    //If the script finds either .jpg or .gif or .png as the
    //ending of your input, it will display the image automatically.
    //The sort order of the elements displayed and therefor within this
    //array is: BACK - START - STOP - FWD
 
 
var be_0= new be_slideshow("0",pics1,"slideshow",400,300,"#ccc",1,1,20,"n","n","y",buttons1);
    //This line calls the slideshow-function.
    //We will have a closer look at it below.
 
</script>
    //But first we close our SCRIPT-Tag.
 
OK, now we analyze the line with the call of the slideshow-function:
 
var be_0= new be_slideshow("0",pics1,"slideshow",400,300,"#ccc",1,1,20,"n","n","y",buttons1);
 
var be_0
The current instance of the slideshow is set as a variable called be_0. The name is obligatory. For 1 slideshow it´s always be_0.
be_slideshow()
be_slideshow() is the name of the function that creates and controls the slideshow. Within the brackets we may assign up to 13 parameter-values. Why "up to"?
Just because we have the possibility to set a DEFAULT-value within the scriptfile. If we do not assign a value within the call, the function tries to use the DEFAULT-value.
If we have multiple slideshows within a website, that vary only in the pictures used, we have the possiblity to put our settings into the scriptfile once (I suggest to do so anyway) and in the single page only set the array with the images and call the slideshow such as:
var be_0= new be_slideshow("0",pics1);
Notice: You don´t have to assign all parameters within the call, but you may not omit a parameter within the row and you have to follow the sort-order. If we want to assign a specific value to the third parameter, we have to assign values to the parameters one and two also. If we need a specific setting for parameter 13, the parameters 1-12 have to be assigned values too. Lets have a look at the parameters:
 
var be_0= new be_slideshow("0");
    //The 1. parameter is the number of the slideshow, starting with "0"
    //The Zero corresponds with the Zero in the name of the variable be_0
    //(We will deal with the question wy we need a number for just 1 slideshow
    // in sample 03.)
 
var be_0= new be_slideshow("0",pics1);
    //The 2. parameter is the name of the parameter, we set for the array with
    //the pictures - in this sample its pics1.
    //The default for this parameter is set in the scriptfile by the parameter: def_imges
 
var be_0= new be_slideshow("0",pics1,"slideshow");
    //The 3. parameter is the IDENTITY of the DIV-Container,
    //we will create to hold our slideshow.
    //The default for this parameter is set in the scriptfile by the parameter: def_divid
 
var be_0= new be_slideshow("0",pics1,"slideshow",400);
    //The 4. parameter is the width of the widest picture in pixel.
    //Notice: The script does not scale your pictures!
    //The default for this parameter is set in the scriptfile by the parameter: def_picwid
 
var be_0= new be_slideshow("0",pics1,"slideshow",400,300);
    //The 5. parameter is the height of the highest picture in pixel.
    //Notice: The script does not scale your pictures!
    //The default for this parameter is set in the scriptfile by the parameter: def_pichei
 
var be_0= new be_slideshow("0",pics1,"slideshow",400,300,"#ccc");
    //The 6. parameter id the background-color of the slideshow. It is of importance
    //if you have pictures in your set, that do not fit the values
    //set above for width and height.
    //The default for this parameter is set in the scriptfile by the parameter: def_backgr
 
var be_0= new be_slideshow("0",pics1,"slideshow",400,300,"#ccc",1);
    //The 7. parameter is the time, a picture is shown between
    //two transitions in seconds.
    //The default for this parameter is set in the scriptfile by the parameter: def_sdur
 
var be_0= new be_slideshow("0",pics1,"slideshow",400,300,"#ccc",1,1);
    //The 8. parameter is the time the transition should take
    //The default for this parameter is set in the scriptfile by the parameter: def_fdur
 
var be_0= new be_slideshow("0",pics1,"slideshow",400,300,"#ccc",1,1,20);
    //The 9. parameter is zhe number of steps to blend from 0-100.
    //A value between 1-100, the higher the value
    //the smoother the transition.
    //The default for this parameter is set in the scriptfile by the parameter: def_steps
 
var be_0= new be_slideshow("0",pics1,"slideshow",400,300,"#ccc",1,1,20,"n");
    //The 10. parameter sets how to start:
    //Should the slideshow start automatically?
    //"y" for Yes, "n" for No
    //The default for this parameter is set in the scriptfile by the parameter: def_startwhen
 
var be_0= new be_slideshow("0",pics1,"slideshow",400,300,"#ccc",1,1,20,"n","n");
    //The 11. parameter sets the start-picture.
    //Should we start with a random picture?
    //"y" for Yes, "n" for No
    //The default for this parameter is set in the scriptfile by the parameter: def_shuffle
 
var be_0= new be_slideshow("0",pics1,"slideshow",400,300,"#ccc",1,1,20,"n","n","y");
    //The 12. parameter sets wheter to show controls or not.
    //"y" for Yes, "n" for No
    //The default for this parameter is set in the scriptfile by the parameter: def_showcontr
 
var be_0= new be_slideshow("0",pics1,"slideshow",400,300,"#ccc",1,1,20,"n","n","y",buttons1);
    //The 13. parameter sets the contents of the control-links.
    //if you show control elements, you may choose between textlinks
    //and buttons. Into this array therefor insert either the text
    //you want to be displayed or the path to the image you want to
    //be used. If the script finds either .jpg or .gif or .png as the
    //ending of your input, it will display the image automatically.
    //The sort order of the elements displayed and therefor within this
    //array is: BACK - START - STOP - FWD
    //The default for this parameter is set in the scriptfile by the parameter: def_contr
 
var be_0= new be_slideshow("0",pics1,"slideshow",400,300,"#ccc",1,1,20,"n","n","y",buttons1);
    //Once again the complete call.
The second step is to create a DIV-container in the BODY-section of your page, located where you want the slideshow to be displayed. Of importance is the IDENTITY of this DIV-container - in this sample it´s "slideshow" (id="slideshow"). It can be chosen, within the call above we have set it as value of a parameter. The DIV-container can be positioned and styled as you want. This sample inserts on of the pictures - uploaded to a subfolder called "pics" - statically into the DIV-container to provide a fallback for visitors without JavaScript. For visitors with JavaScript enabled this is of no importance, because the script replaces the content of the DIV-container with the slideshow.

<div id="slideshow" style="margin:25px;">
  <img src="pics/pic01a.jpg" style="width:400px;height:300px;" />
</div>

That´s it for the webpage.


be_slide.js - the scriptfile

In the downloaded JavaScript-file "be_slide.js" we now should set the DEFAULT-values (the are described in sample 01).
Essential - if we want to use the script-file with different slideshows - is to remove or better disable the DEFAULT-call of the function be_slideshow(). To do this we go to the last line in the scriptfile:
var be_0= new be_slideshow();
and add two slashes at the begin of the line, the start of a one-line comment:
//var be_0= new be_slideshow();
Having done this, the DEFAULT-call is disabled and the call in the HEAD-section of our webpage may do the job.

 


That´s it, have fun with the script.
Last Updated on Thursday, 26 November 2009 18:49
 
Comments (10)
Frage
10 Monday, 14 June 2010 20:55
Simon Frauenschuh

Hallo, das script ist seh rschön, nur habe ich verschiedene Bildgrößen, so ist mein Problem das das bläd aussieht wenn die buttons einen abstabd vom Bild haben, wie kann ich machen das das script dieBildgröße automatisch erkennt?! geht das irgentwie??


Dnake Simon

@Simon Frauenschuh
Tuesday, 15 June 2010 20:33
A. Berger

Hallo Simon!

Nein, das Script skaliert größere Bilder auf die Maximalabmessungen, die Du in der Konfiguration festgelegt hast und versucht kleinere Bilder in dieser Fläche zu skalieren. Weitere Anpassungen werden nicht vorgenommen und das wird sich auch nicht ändern.

Trotzdem, verschieden große Bilder sind in der Regel kein unabwendbares Schicksal. Es gibt genug freie Bildbearbeitungssoftware wie z.B. GIMP mit der sich ausgezeichnet arbeiten lässt und schlußendlich bist immer noch Du der Webmaster und hast es in der Hand, die Bilder offline zu skalieren. Das Resultat auf der Seite ist bei gleich großen Bildern ohnehin das Beste und darauf kommt es schlußendlich ja an.
Also, anstatt einen Missstand programmatisch zu verwalten - kann man ihn ja auch einfach beseitigen. :)

Gruß
Andreas

Fehler
9 Wednesday, 28 April 2010 18:56
Roger lemon

Hey ich hab ein Problem, ich kenne mich mit java nicht aus und verstehe das nicht!! kann mir vllt jemand das vollständige script shcicken?? vllt verstehe ich es dann!! also von obe bis unten nichts auslassen, ich bin anfänger! lasst ruhig eure bilder drinnen sonst verpeil ich das womöglich auch noch danke!

@Quirin Kraus
Saturday, 08 May 2010 16:59
A. Berger

Hallo Quirin!

Das Script verwendet die zIndex-Levels 1 und 2. Es sollte also reichen, wenn Du den Header Container auf 3 setzt.

Gruß
Andreas

PS.: Danke für den in Aussicht gestellten Link!

Danke ist sehr schön
Thursday, 06 May 2010 07:21
Quirin Kraus

okay! Das ist hervorragend, also sowohl das script als auch der rest, bei eanderen seiten war oftmals werbung oder so dabei! Wenn du willst verlink ich dich, wenn meine hp onlin eis drauf! Aber nocheine frage ich hab das script jez mit meinen bildern voll gepumpt... aber jez hab ich ein Problem wenn man auf meiner seite hochscollt dann sieht man das Bild über dem Header.container, welcher eig immer im vordegrund bleiben sollte! Das muss ich ja mit dem z-index verstellen glaub ich oder? bzw was muss ich für einen z-index angeben?!


Vielen Dank Quirin

@Quirin
Wednesday, 05 May 2010 20:10
A. Berger

Hallo Quirin!

Welche Werbung? Du hast mit dem Download ein voll funktionsfähiges Beispiel. Schau es Dir an, schau Dir den Quelltext der Seite an, schau Dir das Script selbst an. Es gibt keine Werbung. Und da das Script nicht irgendwie verschlüsselt ist, lässt sich da weder etwas verstecken noch gibt es eine Funktion, die etwas nachlädt.

Also - viel Spaß damit!
Andreas

Frage 2
Wednesday, 05 May 2010 15:49
Roger Lemon aka Quirin Kraus...

Oke gut das hab ich nun gefudnen, aber wie ist das mit werbung? WIrd dann dort stehen eine addresse von dir oder wie?? ist diese script werbe frei, wenn nicht wie viel werbung ist da bzw wo?!

LG Quirin

@Roger Lemon
Thursday, 29 April 2010 18:04
A. Berger

Hallo Roger Lemon aka Quirin Kraus!

Du kannst das gesamte Script auf der Seite "Slideshow" (http://www.bretteleben.de/lang-de/javascript/slideshow.html) herunterladen (Am Ende des Content, vor den Kommentaren). Das empfiehlt sich alleine schon deshalb, weil es schwierig ist, jemandem etwas zu schicken, von dem man keine Adresse hat. ;)

Betreffend der Bilder - das ZIP enthält ein funktionierendes Beispiel.

Gruß
Andreas

Kommentar zurückziehen
8 Monday, 19 April 2010 09:24
Jenny

hi

möchte meinen Kommentar zurück ziehen, da es jetzt funktioniert....
aber leider funktioniert es noch nicht wenn ich mehrere slideshows einfüge
es läuft immer nur die erste die anderen wechseln nicht automatisch

@Jenny
Tuesday, 20 April 2010 20:11
A. Berger

Hallo Jenny!

In dem Fall würde ich das Problem einfach zurückstellen. Melde Dich sobald die Seite online ist, der Fehler ist dann sicher schnell gefunden.

Gruß
Andreas

hi
Tuesday, 20 April 2010 08:38
Jenny

Kann leider kein link zur seite machen, da diese noch im komplettaufbau ist und somit auf noch keinem server.


das komische ist ja bei der 2 slideshow wechseln die bilder nur beim neuladen des seite

@Jenny
Monday, 19 April 2010 18:10
A. Berger

Hallo Jenny!

Wenn Du einen Link zur Seite postest, schau ich mir gerne an woran es liegt.

Gruß
Andreas

Hilfe!!
7 Monday, 19 April 2010 08:49
Jenny

hab ein großes Problem....
bei mir läuft diese slideshow nicht..
hab alles genauso gemacht wie in der Anleitung beschrieben, aber sie startet nicht sehe immer nur das erste bild
wer kann mir helfen...

@Michael
6 Wednesday, 26 August 2009 17:11
A. Berger
Hallo Michael!

Du kannst den Array mit den Bildern nicht nur im JavaScript-file sondern auch direkt in der Seite befüllen. Nachdem Deine Bilder in einer Datenbank liegen, nehme ich an, dass Dir auch eine serverseitige Scriptsprache (PHP, ASP, ...) zur Verfügung steht, mit der Du das realisieren kannst.
Nachdem Du es geschafft hast, die Bilder IN die Datenbank zu bekommen, bin ich guter Dinge, dass Du sie auch wieder AUS der Datenbank bekommst. Das Slideshow-Script ist in der Hinsicht als rein clientseitiges Script lediglich das ausführende Organ.

Gruß
Andreas
Slideshow
5 Wednesday, 26 August 2009 12:25
Michael
Hi!

Zuerst möchte ich einmal sagen, echt tolles Skript!

Ich möchte das ganze gern in meine Website einbauen aber ich hab ein Problem. Kann man das ganze auch verwenden, wenn die Bilder in einer Datenbank sind?

Mfg Michael
@Ralf P. Zimmermann
4 Monday, 29 June 2009 19:06
A. Berger
Hallo Ralf!

Das liegt daran, dass der DIV-Container, der die Slideshow enthalten soll und das Script nicht im selben Fenster liegen. Vielleicht magst Du Dir ja auf selfhtml.org oder der Seite Deiner Wahl die entsprechenden Punkte durchlesen, bei denen es um das Ansprechen von Scripts im oder aus dem Parent-Frame geht.

Gruß
Andreas
Problem bei Zweitfenster (Popup)
3 Monday, 29 June 2009 12:58
Ralf P. Zimmermann
Hallo Andreas,

herzlichen Dank für Deine Slideshow. Hat mir sehr viel Arbeit erspart.
Allerdings habe ich Probleme, die Slideshow auf einem Popup-Fenster laufen zu lassen. Es erscheint nur das Ersatzbild, das man im DIV angibt. Auch die Buttons erscheinen nicht.

Kannst Du mir da weiterhelfen?

Vielen Dank schon im Voraus.
thansk
2 Thursday, 25 June 2009 17:53
fede
dude thanks a lot u saved me hours of work of going to flash and doing each transition with over 200 images! thanks keep up the good work!
Slideshow
1 Saturday, 07 March 2009 14:42
Djordje
Excellent!
English
Panoramic Image Viewer
AddThis Social Bookmark Button
Who's Online
We have 25 guests online
Latest Items