所以我希望整個頁面能夠覆蓋上一頁。但只有背景變化,所有的文字都可以立即看到。我該如何解決這個問題
請看看自己..
<style>
*{
margin: 0;
padding: 0;
}
ul{
list-style: none;
font-size: 4em;
}
#a{
position: absolute;
top: 0px;
left: 0px;
overflow: hidden;
}
.btn{
position: fixed;
background: white;
z-index: 999;
cursor: pointer;
}
.next{
right: 0;
top: 20px;
}
.prev{
right: 0;
top: 40px;
}
</style>
<body>
<div class="btn next">Next</div>
<div class="btn prev">Prev</div>
<div id="a">
<ul>
<li>aaa</li>
<li>bbb</li>
<li>ccc</li>
<li>ccc</li>
</ul>
</div>
</body>
和JavaScript這樣的:
$(document).ready(function(){
$('li:nth-child(1)').css({'background':'lightgreen', 'z-index':'1'});
$('li:nth-child(2)').css({'background':'gray', 'z-index':'2'});
$('li:nth-child(3)').css({'background':'yellow', 'z-index':'3'});
$('li:nth-child(4)').css({'background':'teal', 'z-index':'4'});
var width = $(window).width();
var height = $(window).height();
$('#a').css({'height':height, 'width':width});
$('li').css({'height':height, 'width':width});
var theFirst = 2;
$('.next').click(function(){
if(theFirst == 2){
$('li:nth-child(2)').animate({'margin-top':'-='+height}, 1500);
theFirst++;
}else if(theFirst == 3){
$('li:nth-child(3)').animate({'margin-top':'-='+height}, 1500);
theFirst++;
}else if(theFirst == 4){
$('li:nth-child(4)').animate({'margin-top':'-='+height}, 1500);
theFirst++;
}else if(theFirst == 5){
$('li:nth-child(5)').animate({'margin-top':'-='+height}, 1500);
}else{
null;
}
});
});
和的jsfiddle是: https://jsfiddle.net/manukarki/wmzskcdq/2/
好吧,那很容易。謝謝 :)。 –
@ManuKarki不客氣。你可能也不需要z索引。 –