溢出容器可见弹出模式

时间:2019-03-19 17:13:38

标签: jquery html css

我需要能够将.popover以外的visible .container保留在scroll容器中。

问题出在第一个button中,其中.popover隐藏在容器溢出的后面。

$(".button").click(function() {
  var popover = $(this)
    .closest(".item")
    .find(".popover");
  popover.toggleClass("is-visible");
});
.container {
  height: 200px;
  border: 2px solid;
  overflow: auto;
  width: 200px;
}

.item {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  height: 150px;
  border: 1px solid blue;
}

button {
  padding: 12px 24px;
  font-size: 16px;
  z-index: 2;
  color: #000;
  min-width: 72px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  background-color: #ffa500;
  outline: none;
}

.popover {
  opacity: 0;
  position: absolute;
  padding: 30px;
  color: #000;
  visibility: hidden;
  text-align: center;
  background: #fff;
  border-radius: 5px;
  box-shadow: 0 18px 35px rgba(50, 50, 93, 0.1), 0 8px 15px rgba(0, 0, 0, 0.07);
}

.popover.is-visible {
  opacity: 1;
  visibility: visible;
}

.popover:after {
  content: "";
  display: block;
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
}

.popover.popover--top {
  left: 50%;
  bottom: 75%;
  -webkit-transform: translate(-50%, 0px);
  transform: translate(-50%, 0px);
}

.popover.popover--top:after {
  top: calc(100% - 6px);
  right: calc(50% - 6px);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
  <div class="item">
    <button class="button">Button</button>
    <div class="popover popover--top">
      <h2>Pop</h2>
    </div>
  </div>
  <div class="item">
    <button class="button">Button</button>
    <div class="popover popover--top">
      <h2>Pop</h2>
    </div>
  </div>
</div>

0 个答案:

没有答案