【问题标题】:bootstrap modal backdrop remain static when scroll滚动时引导模式背景保持静止
【发布时间】:2017-11-29 00:08:04
【问题描述】:

当我单击按钮时,我遇到了引导模式背景的问题,模式显示已启动,我创建了一个函数,当我在选择标签上选择某些内容时将附加该函数,因此模式本身将调整大小,但背景仍然是同样的,当我滚动时会留下一个空间..

这是我的模态

<div class="modal fade" id="accounting" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
  <div class="modal-dialog">
      <div class="modal-content">
          <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
              <h4 class="modal-title">Create Transaction</h4>
          </div>
          <div class="modal-body">

             <form role="form" id="form-transaction">

                <div class="form-group col-sm-12">
                    <label for="transact_2" class="col-sm-12">Transaction</label>
                    <div class="col-sm-12">
                      <select class="form-control" id="entry_2" name="entry_2">
                        <option selected="true" disabled="">Select Entry</option>
                        <option value="credit">Credit</option>
                        <option value="debit">Debit</option>
                      </select>

                    </div>
                </div>
                <div id="cash_receiver">

                </div>

                <div class="form-group">
                  <button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
                  <button class="btn btn-success" type="submit">Save changes</button>
                </div>

            </form>

          </div>
      </div>
  </div>
</div>

这是我根据所选数据附加输入框的脚本

$(document).on('change', '#entry_2', function(){
    entry_2= $(this).val();

    if(entry_2== 'cash'){
        $('#accounting').find('#cash_receiver').addClass('form-group col-sm-12');
        $('#accounting').find('#cash_receiver').html('<label for="manager-2" class="col-sm-12">Name of Receiver</label>'+
                    '<div class="col-sm-12">'+
                      '<input type="text" class="form-control" id="receiver_2" name="receiver_2" placeholder="Name of Receiver">'+
                      '<p class="help-block"></p>'+
                    '</div>');
    }else{
        $('#accounting').find('#cash_receiver').addClass('form-group col-sm-12');
        $('#accounting').find('#cash_receiver').html('<label for="manager-2" class="col-sm-12">Name of Bank</label>'+
                    '<div class="col-sm-12">'+
                      '<input type="text" class="form-control" id="receiver_2" name="receiver_2" placeholder="Name of Bank">'+
                      '<p class="help-block"></p>'+
                    '</div>');
    }
});

正如您在图像上看到的那样,添加输入框时会发生什么......当我向下滚动时,背景保持静止......我之前使用了data-backdrop=false,发生的事情是背景不透明度丢失。有没有办法在模态调整大小时自动填充背景?..

【问题讨论】:

  • 你能提供一个小提琴吗

标签: javascript jquery html css twitter-bootstrap


【解决方案1】:

您应该做的就是将以下 CSS 应用于模态:

.modal{
  position:fixed;
  z-index:9999; /* On top of everything */
}

模态框现在不会随着背景滚动。您还可以添加以下内容:

.modal{
   background-color:rgba(0,0,0,0.5); /* To darken background */
}

现在,在.modal 中添加另一个元素,例如:

<div class="modal"
  <div class="content">
     TEXT
  </div>
</div>  

您现在可以添加:

.content{
   background-color:#fff;
   width:500px; /*on large screens*/
   max-width:100%; /*on small screens*/
}

您现在可以得到想要的效果。请提供更多详细信息,以便我更好地帮助您。

【讨论】:

  • 我得到的唯一问题是当模态内容调整模态背景的大小不符合我提供的图像上发生的情况时...我尝试了您提供的方法,但仍然无法正常工作当输入框追加时。
  • @LionSmith 我不明白你的问题是什么。你能提供你使用的代码吗?
  • @LionSmith 在图像中,黑色背景低于视口高度。根据我的说法,我的代码没有显示出这个问题。
  • 是的......当我在选择标签上选择一个值时会发生这种情况。我现在做的是当我从选择标签中选择一个数据时,它会附加另一个输入框它工作正常但问题是模态短裤的黑色背景..
  • @LionSmith 好的,我明白了。请分享您的代码,以便我指出您的错误。你制作了一个 jsfiddle 甚至是一个 SO sn-p。
猜你喜欢
  • 2015-04-15
  • 2017-12-17
  • 1970-01-01
  • 2018-05-30
  • 1970-01-01
  • 2017-01-06
  • 1970-01-01
  • 2023-03-30
  • 2013-10-09
相关资源
最近更新 更多