简体   繁体   English

弹出窗口不可滚动

[英]Popup window not scrollable

I know this is probably a basic question, but I've tried every solution out there and I can't seem to get my popup window to scroll vertically. 我知道这可能是一个基本问题,但是我尝试了所有解决方案,但似乎无法使弹出窗口垂直滚动。

So I have a 'p' element that an individual can click on and show several reviews. 因此,我有一个“ p”元素,个人可以单击并显示几条评论。 The window pops open, however, the text within the popup window extends beyond the bottom without it being scrollable. 窗口弹出,但是,弹出窗口中的文本超出了底部,无法滚动。

Any help to get the window scrollable is appreciated. 任何帮助使窗口可滚动的帮助都值得赞赏。

 var modal = document.getElementById('myModal'); var btn = document.getElementById('myBtn'); var span = document.getElementsByClassName('close')[0]; btn.onclick = function() { modal.style.display = "block"; } span.onclick = function() { modal.style.display = "none"; } window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } 
 .modal { display: none; position: fixed; z-index: 1; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0.4); } .modal-content { background-color: #fefefe; margin: 15% auto; padding: 20px; overflow: auto; border: 1px solid #888; width: 80%; } .close { color: #aaa; float: right; font-size: 28px; font-weight: bold; } .close:hover, .close:focus { color: black; text-decoration: none; cursor: pointer; } 
 <p id="myBtn">See what our customers are saying</p> <div id="myModal" class="modal"> <div class="modal-content"> <span class="close">&times;</span> <p>...</p> <p>...</p> <p>...</p> <p>...</p> </div> </div> 

 var modal = document.getElementById('myModal'); var btn = document.getElementById('myBtn'); var span = document.getElementsByClassName('close')[0]; btn.onclick = function() { modal.style.display = "block"; } span.onclick = function() { modal.style.display = "none"; } window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } 
 .modal { display: none; position: fixed; z-index: 1; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0.4); } .modal-content { background-color: #fefefe; margin: 15% auto; padding: 20px; overflow: auto; border: 1px solid #888; width: 80%; } .close { color: #aaa; float: right; font-size: 28px; font-weight: bold; } .close:hover, .close:focus { color: black; text-decoration: none; cursor: pointer; } .close{ position:fixed; position: fixed; right: 70px; top: 115px; } .modal-content{ height:100px; overflow-y:scroll; } 
 <p id="myBtn">See what our customers are saying</p> <div id="myModal" class="modal"> <div class="modal-content"> <span class="close">&times;</span> <p>...</p> <p>...</p> <p>...</p> <p>...</p> </div> </div> 

is this right ? 这是正确的吗 ?

You only need to add an specific height in your modal-content class (50% for example): 您只需要在modal-content类中添加特定的高度(例如50%):

https://jsfiddle.net/8p0moxjz/ https://jsfiddle.net/8p0moxjz/

Try adding overflow-y:scroll; 尝试添加overflow-y:scroll; to your modal-content css. 到您的modal-content css。 This will allow scrolling along the y-axis (vertically). 这将允许沿y轴(垂直)滚动。

Modal scroll 模态滚动

Maybe this fiddle can help you. 也许这个小提琴可以帮助您。

I just added height into 'modal-header' and 'modal-content'. 我只是在'modal-header'和'modal-content'中增加了height

Also move border from 'modal-content' into 'modal'. 也将border从“模态内容”转换为“模态”。

If you add 'modal header' class, you can see close button always. 如果添加“模式标头”类,则始终可以看到关闭按钮。

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

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