I am trying to configure fancybox so that when I click one of the 4 images displayed on the page, this is the one that loads in the fancybox window.
For this, I want to use the jquery.attr function to transfer the src image (as a variable) to the main image holder.
My current jquery code is:
jQuery(document).ready(function($) {
$("a.group").click(function() {
var image = $(this).attr("name");
$("#largeId").attr({ src: image});
$("a.group").fancybox({
'frameWidth':966,
'frameHeight': 547,
'hideOnContentClick': false,
'overlayOpacity': 0.85,
'callbackOnShow': function() {
$("#container ul#thumbnails li a").click(function(){
var largePath = $(this).attr("title");
$("#largeId").fadeOut("fast").hide();
$("#largeId").attr({ src: largePath });
$("#largeId").fadeIn("slow");return false;
});
$("#container ul#thumbnails li a").click(function(){
$('.active').removeClass('active');
$(this).addClass("active");
});
}
});
});
});
HTML for homepage images:
<ul id="images">
<li><a id="one_image" class="group" href="#hidden" title="images/1_large.jpg"><img src="Images/1.jpg" alt="MOMA NY #1" title="MOMA NY #1" /></a></li>
<li><a class="group" href="#hidden" title="images/2_large.jpg"><img src="Images/2.jpg" alt="MOMA NY #2" title="MOMA NY #2" /></a></li>
<li><a class="group" href="#hidden" title="images/3_large.jpg"><img src="Images/3.jpg" alt="MOMA NY #3" title="MOMA NY #3" /></a></li>
<li><a class="group" href="#hidden" title="images/4_large.jpg"><img src="Images/4.jpg" alt="MOMA NY #4" title="MOMA NY #4" /></a></li>
</ul>
For the Fancybox window:
<div id="main_image">
<img id="largeId" src="" alt="" title="" />
</div>
------- EDIT ----------
so you know this basically works, if I get rid of the click function first, the functions inside fancybox work fine.
source
share