代码之家  ›  专栏  ›  技术社区  ›  user2587454

使用动画从下至上展开div

  •  0
  • user2587454  · 技术社区  · 6 年前

    我正在尝试从底部到顶部设置按钮高度的动画,并在按钮上方重叠div。

    因此: enter image description here

    我会得到这样的东西: enter image description here

     <div class="div_1"></div>
       <div class="buttons_div">
          <button>1</button>
          <button>2</button>
          <button>3</button>
       </dv>
     <div class="div_1"></div>
    

    https://jsfiddle.net/o2gxgz9r/21096/

    1 回复  |  直到 6 年前
        1
  •  1
  •   Temani Afif BoltClock    6 年前

    您正在设置高度的动画,这是正常的,您还可以设置动画 margin-top 使用负值重叠文本 (如有必要,只需添加高z索引,确保按钮不会位于文本后面)

    $(document).ready(function() {
      $('button').on('click', function(){
      	$(this).animate({'height': '100px','marginTop': '-50px'});
      });
    });
    .div_1{
      width: 300px;
      height: 150px;
      background: blue;
      color: #fff;
    }
    button{
      width: 300px;
      height: 50px;
      border: 0;
      display: block;
      position:relative;
    }
    button:nth-of-type(1){
      background: yellow;
    }
    button:nth-of-type(2){
      background: green;
    }
    button:nth-of-type(3){
      background: orange;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="div_1">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essenti</div>
      <div class="buttons_div">
        <button>1</button>
        <button>2</button>
        <button>3</button>
      </div>
      <div class="div_1"></div>