2016-07-02 19 views

回答

3

自己製作一個很簡單。
的主要步驟包括:

  1. 創建一個div元件,固定於所述頂部,高度零
  2. 把一個按鈕以右上角
  3. 綁定事件到按鈕,當按下時,肘節div的高度。

下面是一個例子:http://codepen.io/SLRXXX/pen/YWVdJZ

$('.button').on('click', function() { 
 
    $('.top').toggleClass('active'); 
 
});
.top { 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    height: 0; 
 
    width: 100%; 
 
} 
 
.strip { 
 
    height: 0; 
 
    background-color: yellow; 
 
    transition: height 0.5s; 
 
    line-height: 40px; 
 
    text-align: center; 
 
    overflow: hidden; 
 
} 
 
.top.active .strip{ 
 
    height: 40px; 
 
} 
 
.button { 
 
    position: absolute; 
 
    top: 0; 
 
    right: 5px; 
 
    width: 40px; 
 
    height: 40px; 
 
    line-height: 40px; 
 
    text-align: center; 
 
    display: inline-block; 
 
    background-color: yellow; 
 
    color: #fff; 
 
    cursor: pointer; 
 
} 
 
.arrow-down { 
 
    transition: transform 0.5s; 
 
} 
 
.top.active .arrow-down{ 
 
    transform: rotate(180deg) 
 
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> 
 

 
<div class="top"> 
 
    <div class="strip"> 
 
    some content 
 
    </div> 
 
    <div class="button"> 
 
    <i class="glyphicon glyphicon-chevron-down arrow-down"></i> 
 
    </div> 
 
</div> 
 

 
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>

+0

完美。我將高度更改爲自動,並且它變得快速響應。 .top.active .strip {height:auto; } – LovingRails