弹出窗口不可滚动

时间:2017-10-12 01:19:03

标签: javascript html css

我知道这可能是一个基本问题,但我已经尝试了所有解决方案,而我似乎无法让我的弹出窗口垂直滚动。

所以我有一个' p'个人可以点击并显示多个评论的元素。窗口弹出打开,但弹出窗口中的文本超出底部而不可滚动。

任何帮助窗口滚动的帮助都表示赞赏。



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>
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:0)

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>

这是对的吗?

答案 1 :(得分:0)

您只需在modal-content课程中添加特定身高(例如50%):

https://jsfiddle.net/8p0moxjz/

答案 2 :(得分:0)

尝试将overflow-y:scroll;添加到modal-content css。这将允许沿y轴(垂直)滚动。

答案 3 :(得分:0)

Modal scroll

也许这个小提琴可以帮助你。

我刚刚将height添加到&#39;模式标题&#39;和&#39;模态内容&#39;。

同时从“模态内容”中移动border&#39;进入&#39;莫代尔&#39;。

如果你添加&#39;模态标题&#39;上课时,你总能看到关闭按钮。