模态窗口接管浏览器的滚动条,就像在Pinterest上一样

Nyx*_*nyx 11 javascript css jquery backbone.js

我有一个模态窗口,它将显示比浏览器窗口高度更长的内容,所以我需要创建一个模态窗口来接管浏览器的滚动条,就像我们在Pinterest上看到的那样.此外,单击图像将导致该图像转换为模态窗口中的图像.

请注意模态的打开如何更改滚动条

在此输入图像描述

问题:如何创建相同的模态窗口(接管滚动条)和图像动画?我知道当模态窗口出现时,浏览器地址栏中的URL会发生变化,但您会注意到该页面并没有真正改变.我能够使用backbone.js这样做,所以不用担心.

HTML代码

<div id="showModal">Click me!</div>

<div class="modal">
    <div class="modal_item">
        <div class="modal_photo_container">
            <img src="img/posts/original/1019_bb8f985db872dc7a1a25fddeb3a6fc3c43981c80.jpg" class="modal_photo">
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

JS代码

$('#showModal').click(function() {
    $('.modal').show();
});
Run Code Online (Sandbox Code Playgroud)

ban*_*aka 22

首先,我建议你的模态的html结构类似于这个:

    <div class="modal-container">
        <div class="modal">
        </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

然后,在"点击",你要补充overflow:hiddenbody,和,不知何故,添加display:block.modal-container..modal-container会有相应的CSS:

.modal-container {
   display: none;
   overflow-y: scroll;
   position: fixed;
   top: 0; right: 0;
   height: 100%; width: 100%; 
}
Run Code Online (Sandbox Code Playgroud)

看看http://jsfiddle.net/joplomacedo/WzA4y/上的一个工作示例