I’ve inserted small image-based navigation arrows inside the fancybox window that allows the user to navigate to related images once fancybox is opened.
Here is the code:
function formatTitle(title, currentArray, currentIndex, currentOpts) {
return '<div id="tip7-title"> (title && title.length ? '<b>' + title + '</b>' : '' ) + '<a href="javascript:;" onclick="$.fancybox.prev();"><img class="left" src="" /></a>' + ' Image ' + (currentIndex + 1) + ' of ' + currentArray.length + ' <a href="javascript:;" onclick="$.fancybox.next();"><img class="right" src="" /></a> </div>';
}
How can I format the arrows so that the left arrow (which points to the previous image) is changed to a different image and is not clickable when the first image is on screen (ie. < Image 1 of 3 > )? Also, the same for the right arrow (which points to the next image) when the third image is on screen (ie. < Image 3 of 3 > ).
Thanks everyone!
Basically you have to validate 3 states and return your (arrow) images accordingly:
When the
currentIndex = 0, the first image is on screen then return a different left arrow image with no<a>tag wrapping it.When the
currentIndex = (currentArray.length - 1), the last image is on screen then return a different right arrow image with no<a>tag wrapping it.Otherwise show both clickable arrows.
BTW, the script you posted above has some syntax errors so I corrected it.
So for a sample gallery with this html:
I will use this script (Fancybox v1.3.x):
and your (modified) “formatTitle” function:
Notice the names I assigned to the arrow images so you will know what image goes where.