Bootstrap 4:为什么在可滚动下拉列表中弹出窗口没有显示?

时间:2018-03-16 11:36:22

标签: javascript jquery css bootstrap-4 bootstrap-popover

我想让它像Bootstrap 3一样工作。当我在悬停弹出窗口上有滚动条的下拉列表时,我认为Bootstrap 4存在问题。我需要溢出:隐藏;制作下拉滚动,但也隐藏了弹出窗口。我尝试使用container:'body',但它没有用。

$(document).ready(function() {
  $('[data-toggle="popover"]').popover({
    html: true,
    container: 'body'
  });
});
.dropdown-menu{
	height: 150px;
	overflow: hidden;
	overflow-y: auto
}
<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap Example</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Dropdowns</h2>
                                     
  <div class="dropdown">
    <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
      Dropdown button
    </button>
    <div class="dropdown-menu">
      <a class="dropdown-item" href="#"	title="Header" data-toggle="popover" data-placement="right" data-trigger="hover"data-content="Some content">Link 1</a></a>
      <a class="dropdown-item" href="#" title="Header" data-toggle="popover" data-placement="right" data-trigger="hover" data-content="Some content">Link 2</a>
      <a class="dropdown-item" href="#">Link 3</a>
      <a class="dropdown-item" href="#">Link 4</a>
      <a class="dropdown-item" href="#">Link 5</a>
      <a class="dropdown-item" href="#">Link 6</a>
      <a class="dropdown-item" href="#">Link 7</a>
      <a class="dropdown-item" href="#">Link 8</a>
      <a class="dropdown-item" href="#">Link 9</a>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:4)

有一些issuespopper.js,以及它如何定位下拉列表,弹出窗口和工具提示。解决方案是将弹出窗口上的 data-boundary 选项设置为window ...

Demo on Codeply

$(document).ready(function() {
  $('[data-toggle="popover"]').popover({
  });
});
.dropdown-menu{
	height: 150px;
	overflow: hidden;
	overflow-y: auto
}
<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap Example</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Dropdowns</h2>
  <div class="dropdown">
    <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
      Dropdown button
    </button>
    <div class="dropdown-menu">
      <a class="dropdown-item" href="#"	title="Header" data-boundary="window" data-toggle="popover" data-placement="right" data-trigger="hover"data-content="Some content">Link 1</a></a>
      <a class="dropdown-item" href="#" title="Header" data-boundary="window" data-toggle="popover" data-placement="right" data-trigger="hover" data-content="Some content">Link 2</a>
      <a class="dropdown-item" href="#">Link 3</a>
      <a class="dropdown-item" href="#">Link 4</a>
      <a class="dropdown-item" href="#">Link 5</a>
      <a class="dropdown-item" href="#">Link 6</a>
      <a class="dropdown-item" href="#">Link 7</a>
      <a class="dropdown-item" href="#">Link 8</a>
      <a class="dropdown-item" href="#">Link 9</a>
    </div>
  </div>
</div>