3

我目前正在使用fancybox 版本2 在单击缩略图时显示我的图像,但我似乎无法让fancybox 垂直放置在视口中间,因为水平方向很好。

我已经尝试了很多东西,这是最新的:

CSS

.fancybox-wrap { 
    position: fixed !important;
    top: 50px !important;
} 

jQuery

jQuery(document).ready(function() {
    $(".fancybox-wrap").css("position", "absolute");

    // fancybox initialisation etc

});


$(window).scroll(function() {
    $('.fancybox-wrap').css('top', $(this).scrollTop() + "50px");
});

有没有人有任何想法?

4

3 回答 3

4

您唯一需要做的就是添加到网站 css

html, body {height: 100%;}

而fancybox 会将图像定位在屏幕中心而不是页面中心。

于 2017-08-24T05:49:34.677 回答
3
$(window).bind('resize', function() {
    var top = ($(window).height() / 2) - ($(".fancybox-wrap").outerHeight() / 2);
    var left = ($(window).width() / 2) - ($(".fancybox-wrap").outerWidth() / 2);
    $(".fancybox-wrap").css({ top: top, left: left});
}).trigger('resize');

http://jsfiddle.net/aGhxK/23/

于 2013-04-23T03:14:08.093 回答
0

这设置lefttop使用position: absolute动态:

http://jsfiddle.net/aGhxK/1/

于 2012-08-22T15:16:14.110 回答