I have a view in my CodeIgniter app. I am using fancybox to display user submitted images from a foreach php loop. My view looks like this:
<ul>
<?php
foreach($photo_strip['photos'] as $photo) { ?>
<li>
<a href="" class="fancybox" rel="group"><img src="<?= $photo->image ?>" alt=""/></a>
</li>
</ul>
here in <li>
elements, I not only display images, but also link them. please note that images being displayed or in a thumbs folder. In order for thumb to display actual image, I am dynamically linking each thumbnail to its parent image by changing href path with Jquery. So here is my jQuery :
$(document).ready(function()
{
$('.fancybox').click(function()
{
var srcPath = $(this).find("img").attr("src");
var newFilename = srcPath.split('/').pop();
var newPath = 'http://example.com/images/trip/' + newFilename;
});
So each time when a user clicks the thumnail saved in the directory: /trip/thumbs/, my jQuery changes the file path and loads actual image from: /trip/ This works well upto this point. But when I add fancybox to it, either it shows only thumbnails except the first clicked image, or it loads the same image despite clicking navigation buttons. So my full script looks like this:
$(document).ready(function()
{
$('.fancybox').click(function()
{
var srcPath = $(this).find("img").attr("src");
var newFilename = srcPath.split('/').pop();
var newPath = 'http://example.com/images/trip/' + newFilename;
$('.fancybox').attr("href", newPath);
$('.fancybox').fancybox({
padding: 0
});
});
});
My problem is: I want to be able to click a single thumb, it opens fancybox, and when I navigate, it should open image from parent directory, not the thumb itself.
Is there anyway to do this?