Adding photo captions, dates, and bylines
You may add captions, dates, and bylines to photos by passing one or more of the three optional parameters of the PhotoViewer's add(imageUrl, caption, date, byline) method:
[...]
var viewer = new PhotoViewer();
viewer.add('photo1.jpg', 'A special photo', '11/01/2006 10:12', 'Amy Smith');
viewer.add('photo2.jpg', 'Holidays in Spain', '07/12/2006 15:43');
viewer.add('photo3.jpg', 'Just another caption');
viewer.add('photo4.jpg');
[...]
Bylines are positioned at the bottom-right corner of the browser window. You can adjust the distance from the bottom and right-hand edges by adding the following parameters at the beginning of the script:
-
BYLINE_POSITION_RIGHT
The amount of space, in pixels, between the byline text and the right-hand edge of the browser window.
-
BYLINE_POSITION_BOTTOM
The amount of space, in pixels, between the byline text and the bottom edge of the browser window.
[...]
BYLINE_POSITION_RIGHT = 30;
BYLINE_POSITION_BOTTOM = 20;
var viewer = new PhotoViewer();
viewer.add('photo1.jpg', 'A special photo', '11/01/2006 10:12', 'Amy Smith');
[...]
Captions, dates, and bylines are added to photos in this example.
Using multiple slideshows
Need multiple slideshow viewers on the same page? No problem! You may create as many PhotoViewer objects as you like, just make sure that they are given different variable names. For example:
[...]
var viewer1 = new PhotoViewer();
viewer1.add('photo1.jpg');
var viewer2 = new PhotoViewer();
viewer2.add('photo2.jpg');
[...]
<a href="javascript:void(viewer1.show(0))">Slideshow 1</a>
<a href="javascript:void(viewer2.show(0))">Slideshow 2</a>
[...]
Customizing the slideshow animation
The following JavaScript methods can be applied to tweak the parameters of the slideshow animation. These methods should be invoked on your PhotoViewer instance:
-
viewer.setSlideDuration(duration);
Sets the time interval between slide transitions, in milliseconds. Default value:4000.
-
viewer.disablePanning(); / viewer.enablePanning();
Disables / enables the panning effect (enabled by default). -
viewer.disableFading(); / viewer.enableFading();
Disables / enables the fade-out/fade-in transitions in slideshow mode (enabled by default). -
viewer.disablePhotoFading(); / viewer.enablePhotoFading()
Disables / enables the fade-out/fade-in tranisitions for manual movement between photos (disabled by default). -
viewer.enableAutoPlay(); / viewer.disableAutoPlay();
If enabled, the slideshow animation starts automatically when the viewer is shown (disabled by default). -
viewer.enableLoop(); / viewer.disableLoop();
If enabled, the slideshow animation will reset to and replay from the first image after the last image had been displayed (disabled by default). -
viewer.randomize();
The slideshow will shuffle your list of images and display them in random order on each page reload.
The example below automatically starts a slideshow while disabling the panning effect:
[...] var viewer = new PhotoViewer(); viewer.setSlideDuration(3000); viewer.disablePanning(); viewer.enableAutoPlay(); [...]The effect can be seen here.
Customizing the viewer's appearance
For those of you wishing to customize the viewer's appearance, here are some additional JavaScript methods. These should be invoked on your PhotoViewer instance:
-
viewer.setBackgroundColor(color);
Sets the photo's background and border color. Thecolorparameter may be a CSS color specification or the keyword “transparent”. Default value:"#000000". -
viewer.setBorderWidth(width);
Sets the photo's border width in pixels. Setting it to0would remove the border. Default value:5. -
viewer.disableShade(); / viewer.enableShade();
Disables / enables the shaded background (enabled by default). -
viewer.setShadeColor(color);
Sets the color of the shaded background. Thecolorparameter should be a CSS color specification. Default value:"#000000". -
viewer.setShadeOpacity(opacity);
Sets the opacity of the shaded background. Theopacityparameter should be a real number between0.0(fully transparent) and1.0(fully opaque). Default value:0.7. -
viewer.setFont(font);
Sets the font that is used to display image numbers and captions. -
viewer.setFontSize(size);
Sets the font size that is used to display image numbers and captions, in pixels. Default value:10pixels.
Here is an example:
[...]
var viewer = new PhotoViewer();
viewer.setBackgroundColor('#ffffff');
viewer.setBorderWidth(2);
viewer.setFontSize(11);
viewer.setShadeColor('#807872');
[...]
...which creates this effect.
Other Customizations
You may disable certain buttons in the photo viewer's toolbar, or hide the toolbar altogether, by using the following methods of your photo viewer instance:
-
viewer.disableEmailLink(); / viewer.enableEmailLink();
Disables / enables the 'email photo' button in the toolbar (enabled by default). -
viewer.disablePhotoLink(); / viewer.enablePhotoLink();
Disables / enables the 'link to photo' button in the toolbar (enabled by default). -
viewer.enableToolbarAnimator(); / viewer.disableToolbarAnimator();
Auto-hides the toolbar after a few seconds of mouse/keyboard inactivity, displays it on mouse movement/click/key press (disabled by default). -
viewer.disableToolbar(); / viewer.enableToolbar();
Hides / shows the toolbar entirely (enabled by default).
The setOnClickEvent method can be used to change the action performed when a user left-clicks on an image displayed by the viewer. This method must be called on the photo viewer instance for which you wish to change the on-click behavior:
-
viewer.setOnClickEvent(viewer.close);
Closes the slideshow viewer (this is the default behavior). -
viewer.setOnClickEvent(viewer.startSlideShow);
Starts and stops the slideshow animation. -
viewer.setOnClickEvent(viewer.permalink);
Opens the currently displayed image in a new browser window when the image is clicked on.
The code below disables the email and photo links and instructs the photo viewer to start or pause the slideshow animation when a users clicks on the image area:
[...] var viewer = new PhotoViewer(); viewer.setOnClickEvent(viewer.startSlideShow); viewer.disableEmailLink(); viewer.disablePhotoLink(); [...]You can preview the above example here.