Rosencrantz
06-24-2005, 09:40 PM
I have modified the DHTML Slide Show Script (http://www.dynamicdrive.com/dynamicindex14/dhtmlslide.htm) to improve the functionality a bit by including a few additional elements.
For example, I was confused by the "Previous Slide" / "Next Slide" links staying the same, regardless of whether or not there WAS a previous or next slide to view. To fix this, I am using images as my navigation elements. Now, when you're at the start or end of the image array, you'll see a different (faded) navigation image.
The issue that I am having trouble with is dynamic CAPTIONS. My JavaScript isn't great, but I figured out how to switch out text dynamically, but only as button values. Can someone make suggestions about how best to make this happen with real text on the page? Maybe with a DIV or SPAN?
See an example here: http://www.symptek.com/slideshow.html
Any suggestions will be appreciated.
Thanks.
R
Here's the code:
<html>
<head>
<title>DHTML Slide Show Script - with improvements</title>
<script type="text/javascript">
/***********************************************
* DHTML slideshow script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice must stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
var photos=new Array()
var photoslink=new Array()
var caption=new Array()
var which=0
var lft_img_on="http://www.symptek.com/dhtml/left_arrow_on.gif"
var lft_img_off="http://www.symptek.com/dhtml/left_arrow_off.gif"
var rt_img_on="http://www.symptek.com/dhtml/right_arrow_on.gif"
var rt_img_off="http://www.symptek.com/dhtml/right_arrow_off.gif"
//define images. You can have as many as you want:
photos[0]="dhtml/photo1.jpg"
photos[1]="dhtml/photo2.jpg"
photos[2]="dhtml/photo3.jpg"
//Specify whether images should be linked or not (1=linked)
var linkornot=0
//Set corresponding URLs for above images. Define ONLY if variable linkornot equals "1"
photoslink[0]=""
photoslink[1]=""
photoslink[2]=""
//Specify whether images should have captions or not (1=captions)
var captions=1
//Set corresponding URLs for above images. Define ONLY if variable linkornot equals "1"
caption[0]="Image 1"
caption[1]="Image 2"
caption[2]="Image 3"
//do NOT edit pass this line
var preloadedimages=new Array()
for (i=0;i<photos.length;i++){
preloadedimages[i]=new Image()
preloadedimages[i].src=photos[i]
}
function applyrighteffect(){
if (document.all && photoslider.filters){
photoslider.filters.revealTrans.Transition=7
photoslider.filters.revealTrans.stop()
photoslider.filters.revealTrans.apply()
}
}
function changecaption() {
document.exf1.caption.value = caption[which];
}
function applylefteffect(){
if (document.all && photoslider.filters){
photoslider.filters.revealTrans.Transition=6
photoslider.filters.revealTrans.stop()
photoslider.filters.revealTrans.apply()
}
}
function playeffect(){
if (document.all && photoslider.filters)
photoslider.filters.revealTrans.play()
}
function keeptrack(){
window.status="Image "+(which+1)+" of "+photos.length
}
function backward(){
if (which==1){
which--
applylefteffect()
document.images.photoslider.src=photos[which]
document.images.lft_img.src=lft_img_off
document.images.rt_img.src=rt_img_on
playeffect()
keeptrack()
changecaption()
} else if (which>0) {
which--
applylefteffect()
document.images.photoslider.src=photos[which]
document.images.lft_img.src=lft_img_on
document.images.rt_img.src=rt_img_on
playeffect()
keeptrack()
changecaption()
} else {
document.images.lft_img.src=lft_img_off
}
}
function forward(){
if (which+1==photos.length-1){
which++
applyrighteffect()
document.images.photoslider.src=photos[which]
document.images.rt_img.src=rt_img_off
document.images.lft_img.src=lft_img_on
playeffect()
keeptrack()
changecaption()
} else if (which<photos.length-1) {
which++
applyrighteffect()
document.images.photoslider.src=photos[which]
document.images.rt_img.src=rt_img_on
document.images.lft_img.src=lft_img_on
playeffect()
keeptrack()
changecaption()
} else {
document.images.rt_img.src=rt_img_off
}
}
function transport(){
window.location=photoslink[which]
}
</script>
</head>
<body>
<table width="100%" height="100%">
<tr>
<td align="center">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="2"><script>
if (linkornot==1)
document.write('<a href="javascript:transport()">')
document.write('<img src="'+photos[0]+'" name="photoslider" style="filter:revealTrans(duration=1,transition=23)" border=0>')
if (linkornot==1)
document.write('</a>')
</script></td>
</tr>
<script>
if (captions==1)
document.write('<tr><td colspan="2" align="center"><form name=exf1><input type=button name=caption value="'+caption[0]+'"></td></tr>')
</script>
<tr>
<td><a href="#" onClick="backward(); return false"><img name="lft_img" src="http://www.symptek.com/dhtml/left_arrow_off.gif" width="25" height="25" alt="" border="0"></a></td>
<td align="right"><a href="#" onClick="forward(); return false"><img name="rt_img" src="http://www.symptek.com/dhtml/right_arrow_on.gif" width="25" height="25" alt="" border="0"></a></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
For example, I was confused by the "Previous Slide" / "Next Slide" links staying the same, regardless of whether or not there WAS a previous or next slide to view. To fix this, I am using images as my navigation elements. Now, when you're at the start or end of the image array, you'll see a different (faded) navigation image.
The issue that I am having trouble with is dynamic CAPTIONS. My JavaScript isn't great, but I figured out how to switch out text dynamically, but only as button values. Can someone make suggestions about how best to make this happen with real text on the page? Maybe with a DIV or SPAN?
See an example here: http://www.symptek.com/slideshow.html
Any suggestions will be appreciated.
Thanks.
R
Here's the code:
<html>
<head>
<title>DHTML Slide Show Script - with improvements</title>
<script type="text/javascript">
/***********************************************
* DHTML slideshow script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice must stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
var photos=new Array()
var photoslink=new Array()
var caption=new Array()
var which=0
var lft_img_on="http://www.symptek.com/dhtml/left_arrow_on.gif"
var lft_img_off="http://www.symptek.com/dhtml/left_arrow_off.gif"
var rt_img_on="http://www.symptek.com/dhtml/right_arrow_on.gif"
var rt_img_off="http://www.symptek.com/dhtml/right_arrow_off.gif"
//define images. You can have as many as you want:
photos[0]="dhtml/photo1.jpg"
photos[1]="dhtml/photo2.jpg"
photos[2]="dhtml/photo3.jpg"
//Specify whether images should be linked or not (1=linked)
var linkornot=0
//Set corresponding URLs for above images. Define ONLY if variable linkornot equals "1"
photoslink[0]=""
photoslink[1]=""
photoslink[2]=""
//Specify whether images should have captions or not (1=captions)
var captions=1
//Set corresponding URLs for above images. Define ONLY if variable linkornot equals "1"
caption[0]="Image 1"
caption[1]="Image 2"
caption[2]="Image 3"
//do NOT edit pass this line
var preloadedimages=new Array()
for (i=0;i<photos.length;i++){
preloadedimages[i]=new Image()
preloadedimages[i].src=photos[i]
}
function applyrighteffect(){
if (document.all && photoslider.filters){
photoslider.filters.revealTrans.Transition=7
photoslider.filters.revealTrans.stop()
photoslider.filters.revealTrans.apply()
}
}
function changecaption() {
document.exf1.caption.value = caption[which];
}
function applylefteffect(){
if (document.all && photoslider.filters){
photoslider.filters.revealTrans.Transition=6
photoslider.filters.revealTrans.stop()
photoslider.filters.revealTrans.apply()
}
}
function playeffect(){
if (document.all && photoslider.filters)
photoslider.filters.revealTrans.play()
}
function keeptrack(){
window.status="Image "+(which+1)+" of "+photos.length
}
function backward(){
if (which==1){
which--
applylefteffect()
document.images.photoslider.src=photos[which]
document.images.lft_img.src=lft_img_off
document.images.rt_img.src=rt_img_on
playeffect()
keeptrack()
changecaption()
} else if (which>0) {
which--
applylefteffect()
document.images.photoslider.src=photos[which]
document.images.lft_img.src=lft_img_on
document.images.rt_img.src=rt_img_on
playeffect()
keeptrack()
changecaption()
} else {
document.images.lft_img.src=lft_img_off
}
}
function forward(){
if (which+1==photos.length-1){
which++
applyrighteffect()
document.images.photoslider.src=photos[which]
document.images.rt_img.src=rt_img_off
document.images.lft_img.src=lft_img_on
playeffect()
keeptrack()
changecaption()
} else if (which<photos.length-1) {
which++
applyrighteffect()
document.images.photoslider.src=photos[which]
document.images.rt_img.src=rt_img_on
document.images.lft_img.src=lft_img_on
playeffect()
keeptrack()
changecaption()
} else {
document.images.rt_img.src=rt_img_off
}
}
function transport(){
window.location=photoslink[which]
}
</script>
</head>
<body>
<table width="100%" height="100%">
<tr>
<td align="center">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="2"><script>
if (linkornot==1)
document.write('<a href="javascript:transport()">')
document.write('<img src="'+photos[0]+'" name="photoslider" style="filter:revealTrans(duration=1,transition=23)" border=0>')
if (linkornot==1)
document.write('</a>')
</script></td>
</tr>
<script>
if (captions==1)
document.write('<tr><td colspan="2" align="center"><form name=exf1><input type=button name=caption value="'+caption[0]+'"></td></tr>')
</script>
<tr>
<td><a href="#" onClick="backward(); return false"><img name="lft_img" src="http://www.symptek.com/dhtml/left_arrow_off.gif" width="25" height="25" alt="" border="0"></a></td>
<td align="right"><a href="#" onClick="forward(); return false"><img name="rt_img" src="http://www.symptek.com/dhtml/right_arrow_on.gif" width="25" height="25" alt="" border="0"></a></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>