I understand this is probably extremely simple but I can't get my head around it. As it stands, I have my lightbox gallery fully working, images popping up when thumbnail selected and then when clicked off returning to main page.
What javascripting code am I missing to make my individual images have individual captions?
Here is part of my html body:
<h1> My Photo Gallery </h1>
<div id="back" onClick="Box();">
</div>
<div id="fore">
<img src="daisyl.jpg" id="changeImg">
<h2>Caption One</h2>
</div>
<div id="thumbnails">
<img src="daisy.jpg" height="150px" width="150px" class="small" onClick="lightBox('daisy.jpg');">
<img src="zigl.jpg" height="150px" width="150px" class="small" onClick="lightBox('zigl.jpg');">
<img src="cork.jpg" height="150px" width="150px" class="small" onClick="lightBox('cork.jpg');"> <img src="tri.jpg" height="150px" width="150px" class="small" onClick="lightBox('tri.jpg');">
</div>
I have four images. At the moment under my 'fore' DIV they all have the same caption "Caption One". For the purpose of yer examples I will call the four captions, "Caption One", "Caption Two.. and so fort :)
My javascript:
<script type="text/javascript">
function lightBox(imgNumber){
var img = document.getElementById('changeImg');
img.src = imgNumber;
document.getElementById('back').style.display = "block";
document.getElementById('fore').style.display = "block";
}
function Box(){
document.getElementById('back').style.display = "none";
document.getElementById('fore').style.display = "none";
}
</script>
If you can help me out it would be greatly appreciated!! I think I gave enough code for ye to work with but if not please let me know :)
Here's my fiddle, the lightbox didnt work on it for me but might for ye, it works for me outside of jsfiddle :)
Working example below. I've added caption, so now your lightbox gets description from ALT tag It's not pretty code but I tried to make it simple for you. In the future I recommend using jQuery for those type of features :)
JSFiddle - http://jsfiddle.net/cx20mdzm/