2016-08-14 64 views
0

需要改變的slideToggle

$("button.filters").click(function(){ 
 
    $("div.second").slideToggle("slow"); 
 
});
.main { 
 
    position: relative; 
 
    display:block; 
 
    height: 320px; 
 
    color: #fff; 
 
    background-color: grey; 
 
} 
 
.first { 
 
    position: absolute; 
 
    bottom: 15%; 
 
    height: 70px; 
 
    background-color: white; 
 
} 
 
.second { 
 
    position: absolute; 
 
    bottom: 0%; 
 
    height: 30px; 
 
    background-color: green; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="main"> 
 
    <div class="first"> 
 
    <p>some content</p> 
 
    <button class="filters">filters</button> 
 
    </div> 
 
    <div class="second"> 
 
    <p>other content</p> 
 
    </div> 
 
</div>
元素的位置

請檢查此琴 https://jsfiddle.net/6d1t5jr8/

我需要幫助從.first格的底部邊框做。第二格到.slideToggle

+0

添加您的代碼/提琴.. – Abhishek

+0

創建一個在這裏工作片斷或至少一個小提琴使問題的一小部分娛樂。 – Iceman

+0

請現在檢查 –

回答

1

問題:

因爲在這樣的bottom:0中,.second的高度DIV從底層做起。

解決辦法:

嘗試包裹.second與包裝。所以幻燈片動畫將從頂部開始。

像這樣:

jQuery(document).ready(function() { 
 
    $("button.filters").click(function(){ 
 
    $("div.second").slideToggle("slow"); 
 
    }); 
 
});
.main { 
 
    position: relative; 
 
    display:block; 
 
    height: 320px; 
 
    color: #fff; 
 
    background-color: grey; 
 
} 
 
.first { 
 
    position: absolute; 
 
    bottom: 15%; 
 
    height: 70px; 
 
    background-color: white; 
 
} 
 
.second-wrapper { 
 
    position: absolute; 
 
    bottom: 0%; 
 
    height: 30px; 
 
} 
 

 
.second { 
 
    display:none; 
 
    background-color: green; 
 
} 
 

 
.second p { 
 
    margin:0; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<div class="main"> 
 
    <div class="first"> 
 
    <p>some content</p> 
 
    <button class="filters">filters</button> 
 
    </div> 
 
    <div class="second-wrapper"> 
 
    <div class="second"> 
 
     <p>other content</p> 
 
    </div> 
 
    </div> 
 
</div>

+0

嘿Mosh,你的代碼正在做我想做的事情,但由於某種原因,一旦第二個元素出現,背景顏色就會消失。 –

+0

'背景顏色消失'你是什麼意思?隱藏:http://i.stack.imgur.com/QDS0f.png。可見:http://i.stack.imgur.com/Min0x.png –

+0

我設法做到了,我需要用相同的背景顏色創建新的div。可能其他一些JavaScript代碼正在造成此錯誤。 –