简体   繁体   English

如何使灯箱滚动灯箱而不是页面

[英]How to make lightbox scroll the lightbox and not the page

I am using the lightbox_me jquery plugin to open a lightbox when a user clicks on a product. 当用户点击产品时,我使用lightbox_me jquery插件打开灯箱。 Often the lightbox content stretches below the fold, and at the moment the right scrollbar moves the entire page when you scroll down. 灯箱内容通常会在折叠下方延伸,当您向下滚动时,右侧滚动条会移动整个页面。

I'd like it to work like the pinterest lightbox, whereby the right scrollbar only scrolls the lightbox, and the rest of the page stays fixed. 我希望它像pinterest灯箱一样工作,右边的滚动条只滚动灯箱,页面的其余部分保持固定。 I've seen a few posts on this, but nothing seems to work for me. 我已经看过几篇关于此的帖子,但似乎没有什么对我有用。

jQuery(function(){


$('.productBoxLink').click(function(e) {
    var box = $(this).siblings(".productLightboxContent").html();
    $('.lightBox').lightbox_me({
        centered: false,
        modalCSS:  {top: '50px'},
        onLoad: function() { 
              $('.productLightbox').html(box);
              $('.productUpdateInner').show();
            },
        onClose: function() {
              $('.productUpdateInner').hide();
            }
        });
    return false;
  });
});


.lightBox {
width: 450px;
background-color: #fff;
top: 400px;
position: fixed;
padding: 30px;
text-align: center;
display: none;
clear: both;
-moz-box-shadow: 0 0 5px #5C5C5C;
-webkit-box-shadow: 0 0 5px #5C5C5C;
box-shadow: 0 0 5px #5C5C5C;
border-radius: 5px;
}

I've read that this can be done with a few changes to my CSS. 我已经读过这可以通过对CSS进行一些更改来完成。 Does anyone know how I can achieve this with the code shown? 有谁知道如何通过显示的代码实现这一目标? Thanks! 谢谢!

Add this to .lightBox: 将此添加到.lightBox:

height:600px; /* You need to set a specific height - px or %*/
overflow-x:scroll; /* Tell the container to scroll if the content goes beyond bounds*/

Update 更新

width:100%;
overflow-x:scroll;

If you want to let it size larger than the viewport, it's most likely because of your position: fixed line. 如果你想让它的大小比视口大,那很可能是因为你的position: fixed线。 Change it to position: absolute and you should be good. 将它改为position: absolute ,你应该是好的。

Both fixed and absolute take the element out of the document flow, so there should be no net change in how it presents, but fixed fixes it to that specific position and forces it to not move ever. 固定和绝对都将元素从文档流中取出,因此它的呈现方式不应该有任何净变化,但是fixed将其fixed到该特定位置并迫使它永远不会移动。

I guess a general answer would be to make the background of the lighbox (ie the content before lightbox; the main content wrapper) position: fixed; 我想一般的答案是制作lighbox的背景(即lightbox之前的内容;主要的内容包装器) position: fixed; and adjust its top value with javascript to a negative value corresponding to the position of user scroll in the moment of lightbox opening. 并使用javascript将其最高值调整为与灯箱打开时刻用户滚动位置对应的负值。 Besides that, the lightbox would need to be position: absolute; 除此之外,灯箱需要是position: absolute; with the same top / left values as if it was fixed. 具有相同的顶部 / 左侧值,就好像它是固定的一样。

When the user closes the lightbox, the previous values would need to be restored. 当用户关闭灯箱时,需要恢复以前的值。

Add to html a class when lightbox is opening. 在灯箱打开时添加到html类。 For example: 例如:

.lightbox-active{overflow:hidden}

Also, your lightbox should have the next style: 此外,您的灯箱应具有下一个样式:

.lightbox{overflow-x:hidden;overflow-y:scroll}

When you close the lightbox, you have remove the lightbox-active class from html. 关闭灯箱时,您已从html中删除灯箱活动类。

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

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