问题
I'm using Fancybox 2 to generate a gallery. As well as text, I'd like to have links in the captions of my photos, if necessary.
Here's the page where I'd like to have links within the captions: http://catjohnson.co.uk/weddings
By simply adding an html link in there (following this answer: In Prettyphoto.js or Fancybox... How to add a link within the caption) it breaks the photo within the gallery.
I've tried following this http://jsfiddle.net/FWTZA/ and although it works, I lose my styling.
I can't seem to get my styling to integrate with the js fiddle code… Here's what I'm doing at the minute, which is working:
$(document).ready(function() {
$(".fancybox").fancybox({
openEffect : 'fade',
closeEffect : 'fade',
nextEffect : 'fade',
prevEffect : 'fade',
helpers : {
title : {
type : 'inside'
},
overlay : {
css : {
'background-color' : '#eee'
}
}
}
});
});
I hope that makes sense!
Thanks for taking a look!
Martin :)
回答1:
For this html
<a class="fancybox" data-title-id="title-1" href="http://fancyapps.com/fancybox/demo/1_b.jpg"><img src="http://fancyapps.com/fancybox/demo/1_s.jpg" alt=""/></a>
<div id="title-1" class="hidden">
This is 1st title. <a href="http://google.com">Some link</a>
</div>
<a class="fancybox" data-title-id="title-2" href="http://fancyapps.com/fancybox/demo/2_b.jpg"><img src="http://fancyapps.com/fancybox/demo/2_s.jpg" alt=""/></a>
<div id="title-2" class="hidden">
This is <b>2nd title</b>. <a href="http://google.com">Some link</a>
</div>
...set the helpers option and don't forget to separate each option with a comma like :
$(".fancybox")
.attr('rel', 'gallery')
.fancybox({
openEffect : 'fade',
closeEffect : 'fade',
nextEffect : 'fade',
prevEffect : 'fade',
helpers : {
title : {
type : 'inside'
},
overlay : {
css : {
'background-color' : '#eee'
}
}
},
beforeLoad: function() {
var el, id = $(this.element).data('title-id');
if (id) {
el = $('#' + id);
if (el.length) {
this.title = el.html();
}
}
}
});
Working example: http://jsfiddle.net/FWTZA/372
回答2:
Here's how we did it, pulling all images and urls out of a database:
$(document).ready(function() {
$.fancybox(
[
{ href : '/images/gallery_pic.php?id=229', title: 'Sample image one', rel : 'fancybox-thumb', class : 'fancybox-thumb'},
{ href : '/images/gallery_pic.php?id=167', title: ' Sample image two <a href="http://www.address" target="_blank">See site</a>', rel : 'fancybox-thumb', class : 'fancybox-thumb'}
],
{
type : 'image',
autoScale : true,
prevEffect : 'none',
nextEffect : 'none',
helpers : {
title : {
type: 'inside',
position: 'top'
},
} // closes helpers
}
);
});
来源:https://stackoverflow.com/questions/11725443/links-within-caption-on-fancybox-2