您可以輕鬆地使用切換類。 I don't recommend doing fadeIn and fadeOut.
CSS
#first {
background-color: red;
height: 250px;
opacity: 1;
-webkit-transition: .25s all ease;
-moz-transition: .25s all ease;
-ms-transition: .25s all ease;
-o-transition: .25s all ease;
transition: .25s all ease;
}
#second {
background-color: green;
height: 250px;
opacity: 1;
-webkit-transition: .25s all ease;
-moz-transition: .25s all ease;
-ms-transition: .25s all ease;
-o-transition: .25s all ease;
transition: .25s all ease;
}
.hidden {
height: 0 !important;
opacity: 0 !important;
}
HTML
<section id="parent">
<div id="first">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus sequi iure, nesciunt laudantium a beatae autem, commodi culpa, quasi vitae sint ad. Itaque repellat cum voluptate, est aut provident ipsum?
</div>
<div id="second" class="hidden">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus sequi iure, nesciunt laudantium a beatae autem, commodi culpa, quasi vitae sint ad. Itaque repellat cum voluptate, est aut provident ipsum?
</div>
</section>
的Javascript
jQuery(document).ready(function(){
$('body').click(function(){
$('#first, #second').toggleClass('hidden');
});
});
小提琴鏈接:https://jsfiddle.net/bngnxty9/
我已經添加了點擊身體事件,你可以在那裏替換你自己的事件。
對不起,也許我不清楚OP中,但試圖讓它下面的內容在轉換過程中四處移動。第一個div淡出,下面的內容跳轉,然後回落,因爲div 2開始淡入。 – thatguylowjwj
閱讀更新的內容:) –
非常感謝您的幫助,這非常接近,但第二個元素淡出到窗口頂部,是否有可能使它填充該部分? – thatguylowjwj