简体   繁体   English

如何在页面中心加载图像-slimbox

[英]how load image in center of page - slimbox

I've a problem with the Slimbox plugin. 我对Slimbox插件有问题。 When I click over an image, image load in bottom page and need scroll page for see image . 当我单击图像时,图像会加载到底部页面,并且需要滚动页面才能看到图像。

but in demo image load in center of page 但在演示图像加载到页面中心

css style CSS风格

#lbImage {
        position: absolute;
        left: 0;
        top: 0;
        border: 10px solid #fff;
        background-repeat: no-repeat;
    }

#lbOverlay {
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    cursor: pointer;
}

#lbCenter, #lbBottomContainer {
   z-index: 9999999999;
   position: fixed;
   left: 50%;
   background-color: #fff;
   top: 30px !important; 
}

that worked for me 对我有用

Open the minified slimbox2.js and find the code: 打开缩小的slimbox2.js并找到代码:

y=E.scrollTop()+(E.height()/2);

(it should be located around column 1100) and replace it with (应位于1100列附近),并替换为

y=E.scrollTop()+(window.innerHeight()/2);

Note: variable names could be different (they are chosen randomly by minifier). 注意:变量名称可以不同(它们由Minifier随机选择)。 You may want to search for ".height()/2" for a start. 您可能需要搜索“ .height()/ 2”作为开始。

The code calculates vertical center position of the window. 该代码计算窗口的垂直中心位置。 The error occurs because jQuery $(window).height property returns wrong value in some cases in latter versions of jQuery, and this causes the box to appear near the bottom of the window, or even under the bottom. 发生错误是因为在某些情况下,jQuery $(window).height属性在jQuery的更高版本中返回错误的值,这导致该框显示在窗口底部附近,甚至在底部下方。

Some solutions for this jQuery bug I found on the web include specifying in the beginning of the HTML file, but this didn't work for me. 我在网上发现的有关jQuery Bug的一些解决方案包括在HTML文件的开头进行指定,但这对我不起作用。

Plain JavaScript solution via window.innerHeight solves the problem for most modern browsers, but doesn't work for IE version 8 and earlier. 通过window.innerHeight的普通JavaScript解决方案可解决大多数现代浏览器的问题,但不适用于IE 8及更早版本。

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

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