简体   繁体   English

如何将图库加载到 Fancybox 中,标题不会改变?

[英]How to load a gallery into Fancybox with Title that does not change?

So, basically, I am playing with Fancy box, and basically, just want a title to remain the same for all images in a gallery that get loaded.所以,基本上,我正在玩 Fancy box,基本上,只是希望画廊中加载的所有图像的标题保持不变。 Yes, I can just keep this as title for all images, however, when changing between images, the title fades in and out like the image does.是的,我可以将其保留为所有图像的标题,但是,在图像之间切换时,标题会像图像一样淡入淡出。 Basically, I don't want the title fading here, I just want the image fading.基本上,我不希望标题在这里褪色,我只希望图像褪色。 Because the Title is always the same.因为标题总是一样的。

Here is a fiddle that shows my current problem here with the Title of a Fancybox image gallery:这是一个小提琴,用 Fancybox 图像库的标题显示了我当前的问题:

http://jsfiddle.net/cce18389/3/ http://jsfiddle.net/cce18389/3/

On all images the title will never change.在所有图像上,标题永远不会改变。 As the title depicts the Image Gallery Name (for now it's just filled with dummy content).正如标题所描述的图片库名称(现在它只是填充了虚拟内容)。

I have thought of how to possibly include HTML also within a fancybox 2.1 Gallery of images, however, I can not do this properly either, looking at this link here: http://jsfiddle.net/svsdx/ which adds content to a div instead, not a photo gallery of images as I would like to do.我想过如何在fancybox 2.1图库中也包含HTML,但是,我也无法正确执行此操作,请查看此链接: http : //jsfiddle.net/svsdx/将内容添加到div相反,不是我想做的图片库。

Here is the code as I have it now:这是我现在拥有的代码:

$(document).ready(function($) {
var galleryTitle = $('#galleryTitleHTML').html();

    $('a.photogallery').fancybox({
        wrapCSS: 'fancy-gallery',
        openEffect: 'fade',
        closeEffect: 'fade',
        title: galleryTitle,
        tpl : {
            wrap : '<div class="fancybox-wrap" tabIndex="-1"><div class="fancybox-outer"><div class="fancybox-inner"></div></div></div>'
        },
        helpers : {
            overlay: {
                css: {'background': 'rgba(0,0,0,0.8)' }
            },
            title: {
                type: 'outside',
                position: 'top'
            },
            thumbs : {
                width: 50,
                height: 50
            }
        }
    });

    $('.open-photo-gallery').click(function(e) {
        e.preventDefault();
        var galleryImagesTotal = $('a.photogallery').length,
            eqToLoad = Math.abs(Math.floor(galleryImagesTotal / 2));

        $('a.photogallery:eq(' + eqToLoad + ')').click();
    });
});

Basically, I would like to pull in a div from the page and place that content above the images.基本上,我想从页面中提取一个 div 并将该内容放在图像上方。 Only way I can see doing this is with the Title, but the title fades as the images fade.我可以看到这样做的唯一方法是使用标题,但标题会随着图像的消失而消失。 Just want to get rid of this fading on the title.只是想摆脱标题上的这种褪色。

Also, I would like the Gallery Title to fill the entire width of the top area, instead of changing to the width of the proportional image.另外,我希望画廊标题填充顶部区域的整个宽度,而不是更改为比例图像的宽度。

Anyway to do this?无论如何要做到这一点?

The only way I see you could do this is appending the title to the fancybox overlay instead.我认为您可以执行此操作的唯一方法是将title附加到fancybox叠加层 You may need to set some styles for the title like :您可能需要为title设置一些样式,例如:

.galleryTitle{
    z-index: 9000;
    color: #fff;
    width: 98%;
    margin: 5px auto;
    text-align: center;
}

Then in your fancybox code you need to add at least the following:然后在您的fancybox代码中,您至少需要添加以下内容:

1). 1)。 A flag to validate if the title has been already appended to the fancybox overlay用于验证title是否已附加到fancybox 覆盖层的标志

var addedTitle = false;

2). 2)。 A beforeShow callback to append the title if this hasn't been appended yet (this prevents the title to be appended multiple times while browsing the gallery)如果尚未附加title使用beforeShow回调来附加title (这可以防止在浏览图库时多次附加title

beforeShow: function () {
    if (!addedTitle) {
        $(".fancybox-overlay").append(galleryTitle)
        addedTitle = true;
    }
}

3). 3)。 An afterClose callback to reset the value of the flag用于重置标志值的afterClose回调

afterClose: function () {
    addedTitle = false;
}

4). 4)。 A fancybox margin option to make room for the title above (this may need to be adjusted to fit your needs)一个花式margin选项,为上面的title腾出空间(这可能需要调整以满足您的需要)

margin: [80, 20, 20, 20] // [top, right, bottom, left]

Note : yes, you need to set all margins.注意:是的,您需要设置所有边距。

See JSFIDDLEJSFIDDLE

PS.附注。 Notice that in order to trigger the gallery you don't need to make a whole bunch of math calculations.请注意,为了触发图库,您无需进行大量数学计算。 Selecting the first item using the .eq() method would be enough :使用.eq()方法选择第一项就足够了:

$('.open-photo-gallery').click(function () {
    $('a.photogallery').eq(0).trigger("click");
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM