Hey all,
I’m trying to implement a photo gallery which allows the user to navigate through a set of images using a previous and next button. I have managed to get the images displaying correctly but i need to have captions applied to each imge.
Below is my javascript code. I realise this is probably an extremely simple question to answer but i’m new to javascript and am having a bit of a mental block!
Any help would be much appreciated!
[CODE]<<script type=”text/javascript”>
// List image names without extension
var myImg= new Array(3)
myImg[0]= “1”;
myImg[1]= “2”;
myImg[2]= “3”;
myImg[3]= “4”;
// Tell browser where to find the image
myImgSrc = “Assets/Editorial/”;
// Tell browser the type of file
myImgEnd = “.jpg”
var i = 0;
// Create function to load image
function loadImg(){
document.imgSrc.src = myImgSrc + myImg[i] + myImgEnd;
}
// Create link function to switch image backward
function prev(){
if(i<1){
var l = i
} else {
var l = i-=1;
}
document.imgSrc.src = myImgSrc + myImg[l] + myImgEnd;
}
// Create link function to switch image forward
function next(){
if(i>2){
var l = i
} else {
var l = i+=1;
}
document.imgSrc.src = myImgSrc + myImg[l] + myImgEnd;
}
// Load function after page loads
window.onload=loadImg;
</script>