jquerynavigationfancyboxfancybox-2

fancybox no navigation buttons for video gallery


I'm using fancybox for some youtube videos and I would like to have navigation buttons (next and previous buttons beside the overlay) exactly like in THIS fiddle.

Here is my fancybox:

$('.fancybox-media')
    .attr('rel', 'playlist')
    .fancybox({
        openEffect: 'none',
        closeEffect: 'none',
        prevEffect: 'none',
        nextEffect: 'none',
        arrows: false,

        helpers: {
            media: {}
        },
        overlay : {
            css: { 'overflow-y': 'hidden' }
        },
        youtube : {
            autoplay: 1,
            hd: 1,
            wmode: 'opaque',    // shows X to close
            vq: 'hd720'         // default 720p hd quality
        },
        beforeShow : function(){
            $("body").css("overflow", "hidden"); // hide body scrollbar
        },
        afterClose: function(){
            $("body").css("overflow", "scroll"); // show body scrollbar
        }
    });

Regarding to this post from JFK, I've put these styles in my css file:

.fancybox-lock {
    margin: 0 !important;
}

.fancybox-nav {
    width: 60px;       
}

.fancybox-nav span {
    visibility: visible;
}

.fancybox-next {
    right: -60px;
}

.fancybox-prev {
    left: -60px;
}

and my html:

<li class="closed">Headline
    <ul>
        <li class="fl"><a class="fancybox-media" href="http://www.youtube.com/watch?v=Dtb5Srdx7iY" rel="playlist"><img class="thumbnail" src="x.jpg"></a></li>
        <li class="fl"><a class="fancybox-media" href="http://www.youtube.com/watch?v=Dtb5Srdx7iY" rel="playlist"><img class="thumbnail" src="x.jpg"></a></li>
    </ul>
</li>

and the implemented stylesheets:

 <!-- FancyBox -->
<script type="text/javascript" src="fancybox/jquery.fancybox.js?v=2.1.4"></script>
<script type="text/javascript" src="fancybox/helpers/jquery.fancybox-media.js?v=1.0.5"></script>
<link rel="stylesheet" type="text/css" href="fancybox/jquery.fancybox.css?v=2.1.4" media="screen" />

I just can't get this to work and I don't know why. I feel like I am missing some files or so.


Solution

  • Well, this post by JFK (me) is more than one year old so that accepted answer might be overruled by the latest versions of fancybox so you should forget about it by now.

    The only css you need is the same as in the fiddle that you refer at begining of your post :

    .fancybox-nav {
        width: 60px;       
    }
    
    .fancybox-nav span {
        visibility: visible;
    }
    
    .fancybox-next {
        right: -60px;
    }
    
    .fancybox-prev {
        left: -60px;
    }
    

    ...then, your jQuery code doesn't need these lines so you can remove them

    overlay : {
        css: { 'overflow-y': 'hidden' }
    }
    beforeShow : function(){
        $("body").css("overflow", "hidden"); // hide body scrollbar
    },
    afterClose: function(){
        $("body").css("overflow", "scroll"); // show body scrollbar
    }
    

    ... since that is already handle by fancybox v2.1.4

    Last, since you said I would like to have navigation buttons (next and previous buttons beside the overlay), then it doesn't make sense to have this option in your code,

    arrows: false
    

    ...does it? so remove it too. See working JSFIDDLE