Display gallery popup outside iframe

2019-09-06 14:54发布

问题:

I read some thread in here, but I haven't found a good solution for gallery item. I am not expery in jQuery so please bear with me here. I have code to display one image outside iframe. But my goal is to add left/right arrow to scroll through my gallery.

I have this script

   <script type="text/javascript">
    $(document).ready(function () {
        $('.fancybox').click(function (e) {
            e.preventDefault();
            parent.$.fancybox({         
                type : "image", // force type of content to image
                href: this.href,
                title: this.title,
                helpers: {
                    title: { type: 'inside' },
                    overlay: {
                        opacity: 0.3
                    } // overlay
                    //, buttons: {}
                } // helpers
            }); // fancybox
        }); // click
    }); 
</script>

and my HTML code is

<a  rel="gallery" class="fancybox" href="images/01.jpg" title="aaasdasdasd"><img alt="" src="thumbnails/01.jpg"/></a>
<a  rel="gallery" class="fancybox" href="images/02.jpg" title="bbsdfsdfsdfdsf"><img alt="" src="thumbnails/02.jpg"/></a>

FancyBox pop up works. But I would like to add arrows to scroll along my "gallery item". I tried adding gallery code .attr('rel', 'gallery') right above parent.$.fancybox({

but the popup just disappear.

Adding openEffect : 'none', closeEffect : 'none', nextEffect : 'none', prevEffect : 'none', padding : 0, margin : [20, 60, 20, 60] // Increase left/right margin

also make the popup disappear.

Is it possible to do that?

回答1:

You may need to create your gallery elements manually first so try

var gallery = [];
jQuery(document).ready(function ($) {
    $(".fancybox").each(function (i) {
        var item = {
            href: this.href,
            title: this.title
        };
        gallery.push(item);
        $(this).on("click", function () {
            parent.$.fancybox(gallery, {
                // API options
                index: i, // starts gallery from clicked item
                type: "image", // force type of content to image
                helpers: {
                    title: {
                        type: 'inside'
                    }
                } // helpers
            }); // fancybox
            return false;
        }); // on
    }); // each
}); // ready


回答2:

Here is the code for FancyBox showing Gallery image outside iframe

<script type="text/javascript">

var gallery = [];

jQuery(document).ready(function($) {
    $(".fancybox").each(function(i) {

            var item = {
                href: this.href,
                title: this.title
            };
            gallery.push(item);     

            $(this).on("click", function() {    
            parent.$.fancybox(gallery, {
                index: i, // starts gallery from clicked item
                type: "image", // force type of content to image
                helpers: {
                    title: {
                        type: 'inside'
                    },
                    overlay: {
                        opacity: 0.3
                    } // overlay
                } // helpers
            }); // fancybox
            return false;
        }); // click
    });
});
</script>

and the html code is like

<a  rel="gallery" class="fancybox" href="images/01.jpg" title="test1"><img alt="" src="thumbnails/01.jpg"/></a>
<a  rel="gallery" class="fancybox" href="images/02.jpg" title="test2"><img alt="" src="thumbnails/02.jpg"/></a>

this works on IE, firefox, safari, but not Chrome.