问题
I have Fancybox set up to display a gallery of 8 pictures. The first one is displayed on the page and opens the gallery when clicked.
What I'm trying to do now is add another gallery, except with HTML content instead of images, so it's like flipping through a book when navigating the gallery. But nothing's appearing when I click the image.
Here's my Fancybox script:
<script type="text/javascript">
$(document).ready(function(){
$("a.fancybox").fancybox({
openEffect : 'none',
closeEffect : 'none',
nextEffect : 'none',
prevEffect : 'none',
nextSpeed : 0,
prevSpeed : 0,
preload : 3,
'padding' : 15,
'speedIn' : 0,
'speedOut' : 0,
'overlayShow' : true
});
});
</script>
And here's the HTML:
<a class='fancybox' rel='{$id}' href=#popuptext><img src='galleryimage.jpg'></a>
<div style='display: none'><div id='popuptext'>Page 1 text</div></div>
<a class='fancybox' rel='{$id}' href=#popuptext'></a>\n
<div style='display: none'><div id='popuptext'>Page 2 text</div></div>
<a class='fancybox' rel='{$id}' href=#popuptext'></a>\n
<div style='display: none'><div id='popuptext'>Page 3 text</div></div>
<a class='fancybox' rel='{$id}' href=#popuptext'></a>\n
<div style='display: none'><div id='popuptext'>Page 4 text</div></div>
回答1:
You cannot have several elements sharing the same ID #popuptext
since IDs should be unique.
You actually need to assign a different ID to each page and a link targeting to each different selector (ID) so you could do :
<a class="fancybox" href="#page1" rel="gallery"><img src="galleryimage.jpg" alt=""/></a>
<div style="display: none">
<a class="fancybox" href="#page2" rel="gallery"></a>
<a class="fancybox" href="#page3" rel="gallery"></a>
<div id="page1">page 1 text lorem ipsum</div>
<div id="page2">page 2 content and more content</div>
<div id="page3">page 3 text blah, blah, blah</div>
</div>
The first link (with image thumbnail) will open the gallery. The other links don't have to be visible neither to have a thumbnail.
Then your scrip will work
$(".fancybox").fancybox({
openEffect: 'none',
closeEffect: 'none',
nextEffect: 'none',
prevEffect: 'none',
nextSpeed: 0,
prevSpeed: 0,
preload: 3,
padding: 15
// 'speedIn' : 0, // not a valid option for v2.x
//'speedOut' : 0, // not a valid option for v2.x
//'overlayShow' : true // not a valid option for v2.x
});
Notice that I commented out some options that are not valid for v2.x. Check the documentation for the options you should be using in v2.x
See JSFIDDLE
来源:https://stackoverflow.com/questions/17026458/displaying-image-text-gallery-with-fancybox-2