简体   繁体   English

随页面滚动的jQuery灯箱插件

[英]jQuery lightbox plugin that scrolls with the page

Some of the JavaScript lightbox effects that I've seen position the lightbox relative to the viewport, so that when you scroll the page you will still see the lightbox. 我见过的一些JavaScript灯箱效果将灯箱相对于视口定位,因此当您滚动页面时,您仍会看到灯箱。

The other kind are the ones that are positioned relative to the page contents. 另一种是相对于页面内容定位的那些。 If you scroll a page containing one of these, the lightbox moves with the rest of the page. 如果您滚动包含其中一个的页面,灯箱将与页面的其余部分一起移动。

I don't know what this second type is called (or if there is even a term for this behaviour). 我不知道第二种类型的调用是什么(或者是否存在这种行为的术语)。

I've looked at FancyBox and SimpleModal , but as far as I know, these are positioned relative to the viewport only. 我看过FancyBoxSimpleModal ,但据我所知,它们只相对于视口定位。

What jQuery plugin allows lightboxes that scroll with the page? 什么jQuery插件允许与页面滚动的灯箱?

that would actually be up to css. 这实际上取决于css。

lightboxes are just divs that are positioned absolutely (they move with the page) or fixed (they are positioned relative to the browser window. 灯箱只是绝对定位的div(它们随页面移动)或固定(它们相对于浏览器窗口定位)。

Basic Lightbox HTML 基本灯箱HTML

<div class="lightbox_wrapper">
<div class="lightbox">
the lightbox content loaded by ajax 由ajax加载的灯箱内容
</div>
</div>

Basic CSS for a scrolling lightbox 滚动灯箱的基本CSS

div.lightbox{ height:250px; div.lightbox {height:250px; width:250px; 宽度:250像素; margin:auto; 保证金:汽车; position:relative; 位置:相对; } }
div.lightbox_wrapper{ height:250px; div.lightbox_wrapper {身高:250px; width:100%; 宽度:100%; top:200px; 顶:200像素; left:0 position:absolute; 左:0 位置:绝对; } }

Basic CSS for a viewport fixed lightbox 视口固定灯箱的基本CSS

div.lightbox{ height:250px; div.lightbox {height:250px; width:250px; 宽度:250像素; margin:auto; 保证金:汽车; position:relative; 位置:相对; } }
div.lightbox_wrapper{ height:250px; div.lightbox_wrapper {身高:250px; width:100%; 宽度:100%; top:200px; 顶:200像素; left:0 position:fixed; 左:0 位置:固定; } }

Now I believe that most of the common lightboxes make you include their css, or they add it to the DOM on load. 现在我相信大多数常见的灯箱会让你包含他们的css,或者他们在加载时将它添加到DOM中。 If they as you to include a css file then just look for the class that declares the properties of a lightbox and change the position method. 如果他们要包含一个css文件,那么只需查找声明灯箱属性的类并更改位置方法。 otherwise you'll have to add the values to your own css and declare them as important like this. 否则你必须将值添加到你自己的CSS中,并将它们声明为这样重要。

CSS property marked as important CSS属性标记为重要

div.lightbox_wrapper{ height:250px; div.lightbox_wrapper {身高:250px; width:100%; 宽度:100%; top:200px; 顶:200像素; left:0 position:fixed !important; 左:0 位置:固定!重要; } }

as for another kind of lightbox, I haven't seen one so you'll have to explain more in a comment below... 至于另一种灯箱,我还没见过,所以你必须在下面的评论中解释更多...

edit your lightbox CSS as below 编辑你的灯箱CSS如下

#lightbox {
  position: fixed;
}

to center your lightbox popup to the window edit the script as below 将灯箱弹出窗口置于窗口中心编辑脚本,如下所示

top = ($window.height()- YOUR_LIGHT_BOX_HIGHT) / 2;

I'm used Lightbox v2.51 and worked well. 我使用Lightbox v2.51并且效果很好。 the only issue is that yet the background is scrolling while the pop up is fixed and centred. 唯一的问题是,当弹出窗口固定并居中时,背景是滚动的。

Robert Hurst is correct in theory, but if you like FancyBox, it supports both modes via configuration 罗伯特赫斯特在理论上是正确的,但如果你喜欢FancyBox,它通过配置支持这两种模式

If you look at bottom of the http://fancybox.net/howto page, it has an option 如果你查看http://fancybox.net/howto页面的底部,它有一个选项

centerOnScroll If true, content is centered when user scrolls page centerOnScroll如果为true,则当用户滚动页面时,内容将居中

here is an example of how you would invoke it: 这是一个如何调用它的示例:

jQuery(document).ready(function(){
    $('#a').fancybox({
      centerOnScroll: false
    });
});

I appreciate that this is an old question, however, I have seen that the JS gurus at designmodo have implemented a version of this very well: 我很欣赏这是一个老问题,但是,我已经看到了designmodo的JS大师们已经很好地实现了这个版本:

http://designmodo.com/startup/#component-grid http://designmodo.com/startup/#component-grid

Take a look at the showLargeImage function within the all.js file. 看一下all.js文件中的showLargeImage函数。

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

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