javascript - 在 jquery 中显示从中间向外扩展的 div

标签 javascript jquery html css show-hide

我想在用户生成触发器时显示我的 div。我想用来显示 div 的动画是这样的 div 从它的中心开始渲染,然后通过在两个方向(向上和向下)扩展来获得它的高度逐步地。这是我尝试过的片段。 div 从左边开始渲染。我想要的是它从其高度的中间开始渲染。

$("#km1").click(function() {
  $(".homePopup").animate({
    width: "730px",
    height: "200px"
  }, 800);
})
.homePopup {
  position: absolute;
  z-index: 100;
  width: 400px;
  background-color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<a href="#" id="km1">Know more</a>
<div class="homePopup"></div>

最佳答案

您也可以为 margin 设置动画以实现此效果。

设置初始 margin-topmargin-bottom 最终 height 的一半;以及 margin-leftmargin-right 最终 width 的一半。然后,当您增加 widthheight 时,同时减少 margin

$("#km1").click(function() {
  $(".homePopup").animate({
    width: "730px",
    height: "200px",
    margin: '0'
  }, 800);
})
.homePopup {
  position: absolute;
  z-index: 100;
  width: 0px;
  margin: 100px 365px;
  background-color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<a href="#" id="km1">Know more</a>
<div class="homePopup"></div>

关于javascript - 在 jquery 中显示从中间向外扩展的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27774696/

相关文章:

javascript - 使用jquery对齐按钮

javascript - 使用Javascript获取CSS的范围输入值

javascript - Node.js API 对于同一请求返回不同的值

javascript - 获取asp :Button Text into a JavaScript function

javascript - d3js :The xaxis time is not showing the complete date value

php - MySql按月、按周的时间戳查询及比较

html - 为什么 Google Chrome 会更改背景不透明度?

jquery方式的Javascript继承

javascript - 溢出-y :scroll in bxSlider (horizontal slider) Part 2

jQuery - 如何在垂直滚动后水平滚动固定的div