可扩展内容

时间:2018-02-13 15:35:50

标签: jquery onclick click

我正在尝试构建可扩展内容的问题。这是代码https://codepen.io/derekb91/pen/ddpdyY,它都可以正常工作,但我希望当您单击后再次显示这些框。因此它会像现在一样扩展并隐藏其他框,但我希望这些框在您单击展开的div后退回。我错过了什么?

$(".clickable").click(function() {
  $(this).closest(".expandable").find(".fillBox").toggle('slow', function() {
    $(this).closest(".expandable").toggleClass("expanded", function() {
      $(".expandable").not(".expanded").hide();
    });
  });
});
.expandable {
  width: 200px;
  height: 200px;
  background: blue;
  position: relative;
  float: left;
  transition: all .3s ease;
  margin: 0 10px 10px 0;
}

.expandable:last-child {
  margin: 0 0 10px 0;
}

.expanded {
  width: 100%;
  height: 400px;
  background: #333;
  margin-bottom: 10px;
}

.fillBox {
  width: 100%;
  height: 100%;
  display: none;
  background: orange;
}

.clickable {
  position: absolute;
  top: 20px;
  left: 50px;
  right: 0;
  margin-right: auto;
  margin-left: auto;
  z-index: 999;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="expandable">
  <button class="clickable">Click Me</button>
  <div class="fillBox"></div>
</div>

<div class="expandable">
  <button class="clickable">Click Me</button>
  <div class="fillBox"></div>
</div>

<div class="expandable">
  <button class="clickable">Click Me</button>
  <div class="fillBox"></div>
</div>

0 个答案:

没有答案