【问题标题】:jQuery - lightbox stay and page scrolljQuery - 灯箱停留和页面滚动
【发布时间】:2017-06-09 21:57:36
【问题描述】:

如何创建一个始终保持文档高度和宽度不变的灯箱,并且当我滚动后面的页面时,灯箱不移动并且页面正在滚动?当我点击链接时,我有一个 CSS 会显示一个灯箱:

function resizeLightbox() {
    var overlay = createOverlay(),
        lightbox = createLightbox();

    overlay.css({
        "width": doc.width(),
        "height": doc.height()
    });

    var width = lightbox.outerWidth(),
        height = lightbox.outerHeight();

    lightbox.css({
        "position": "fixed",
        "width": width,
        "height": height,
        "top": ***, // i remove that
        "left": *** // and that
    });
}



.lightbox__lightbox {
    display: none;
    background: #fff url(../gallery/ring.gif) center center no-repeat;
    z-index: 10000;
    // added sth like this:
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto auto;

}

是的,我发现了错误,问题出在顶部和左侧属性中,我如何动态计算屏幕中间?

我需要编写一个函数来计算屏幕中间的“***”

【问题讨论】:

  • 当询问有关代码引起的问题的问题时,如果您提供人们可以用来重现问题的功能示例,您将获得更好的答案。见:How to create a Minimal, Complete, and Verifiable example。谢谢!
  • 谢谢,但实际上这很难,因为我的灯箱有 200 行,我不想在这里全部粘贴:/ 而且我只是不知道如何冻结我的灯箱窗口 :(

标签: javascript jquery html css


【解决方案1】:

只需添加位置:固定;到灯箱的css

lightbox.css({
            "position":'fixed',
            "width": width,
            "height": height,
            "top": (win.height() / 2) - (height / 2) + doc.scrollTop(),
            "left": (win.width() / 2) - (width / 2) + doc.scrollLeft()
        });

【讨论】:

  • 是的,我听说过,我正在尝试,但是当我更改为固定位置时,灯箱显示超出窗口
  • 你能给我截图吗?
  • 好酷只需要让它居中改变左边的位置例如:“left”: (win.width() - width) / 2
  • 是的,我做到了,灯箱显示在窗口之外,这很奇怪
猜你喜欢
  • 1970-01-01
  • 2014-05-12
  • 1970-01-01
  • 2017-08-24
  • 1970-01-01
  • 2011-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多