You do not have a gallery using the manual .click()
method unless you set all the gallery elements inside the fancybox script itself, for example:
$("#foo2 img").click(function(e) { $.fancybox([ 'images/01.jpg', 'images/02.jpg', // etc ],{ // fancybox options 'type': 'image' // etc. }); // fancybox }); // click
However, to make it work the way you want, and mimic the normal fancybox gallery without using links ( <a>
tags with href
attributes), you will need to create your own function using your own navigation methods.
Without changing the HTML
try JS
:
<script type="text/javascript"> function fancyBoxMe(index){ var gallerySize = $("#foo2 img").size(); if((index+1) == gallerySize){ nexT = 0 } else { nexT = index+1} if(index == 0){ preV = (gallerySize-1) } else { preV = index-1} var tarGet = $('#foo2 img').eq(index).attr('src'); $.fancybox({ 'transitionIn' : 'elastic', 'transitionOut' : 'elastic', 'speedIn' : 600, 'speedOut' : 200, 'overlayShow' : false, 'href': tarGet, 'titlePosition': 'inside', 'titleFormat' : function(){ return 'Image '+(index+1)+' of '+gallerySize+'<a id="preV" href="javascript:;" onclick="fancyBoxMe('+preV+')">prev</a> <a id="nexT" href="javascript:;" onclick="fancyBoxMe('+nexT+')">next</a>'; } }); </script>
This creates a fancybox gallery from <img>
tags, with a smoothing effect. Also, with a bit of CSS
we can control the navigation with the fancybox arrow icons. See a working example here .
Since the navigation control is completely manual, you really don't need the rel
attribute in the <img>
.
Please note that the above code is for Fancybox v1.3.x (I assumed that you are using v1.3.x because the parameters are API).
source share