我剛剛開始使用html(和jQuery)並且無法找出以下問題。如何在slideDown()彼此之間防止圖像閃爍
我正在嘗試製作某種照片滑塊庫。在左邊,相互之間有一些類別,每3-4秒,頂級類別向右滑動(並擴大其寬度)並下降。在下拉菜單中,它會打開特定分類的圖像。爲了使環contineous我需要兩個div,滑下了對方,請看下面的代碼:
<html>
<head>
<title>Galerij</title>
<link rel="stylesheet" type="text/css" href="CSS/CSS_Galerij.css">
<script src="Javascripts/jquery-1.10.2.min.js"></script>
<script>
var But = new Array(
'#But1','#But2','#But3','#But4','#But5','#But6','#But7');
var But_Pos = new Array(
'0px','68px','136px','204px','272px','340px','408px');
var Images = new Array(
"Images/Stoel/Stoel_Alpha_1.jpg",
"Images/Gestoffeerde_Stoel/Gestoffeerde_Stoel_Kokonstoel_1.jpg",
"Images/Schommelstoel/Schommelstoel_Delta_1.jpg",
"Images/Tuinbank/Tuinbank_Beta_1.jpg",
"Images/Kast/Kast_Modulekast_1.jpg",
"Images/Salontafel/Salontafel_Klassiek_1.jpg",
"Images/Overig/Overig_Compartimentendoos_1.jpg");
var Num_But = 7;
var Track_Img = -1;
var Track_Large_Img = 0;
var speed = 1000;
var speed2 = 940;
$(document).ready(function(){
$('#imgl1').attr('src',Images[0]);
$(But[0]).animate({left:'233px',width:'475'},speed).animate({top:'612px'},speed,Set _But_Array);
for (var i=1;i<7;i++) {
$(But[i]).delay(speed).animate({top:But_Pos[i-1]},speed)
}
$('#divimg1').delay(speed).slideDown(speed);
Track_Large_Img++;
});
function Set_But_Array() {
var temp = But[0];
for (var i=1;i<Num_But;i++) {
But[i-1]=But[i];
}
But[(Num_But-1)] = temp;
Loop();
}
function Loop() {
if (Track_Img == -1) {
$('.img2').css('z-index','101');
$('.img1').css('z-index','99');
$('#imgl2').attr('src',Images[Track_Large_Img]);
$('#divimg2').delay(4*speed).slideDown(speed2);
$('#divimg1').delay(5*speed).slideUp(10);
}
else if (Track_Img == 1) {
$('.img1').css('z-index','100');
$('.img2').css('z-index','99');
$('#imgl1').attr('src',Images[Track_Large_Img]);
$('#divimg1').delay(4*speed).slideDown(speed2);
$('#divimg2').delay(5*speed).slideUp(10);
}
$(But[0]).delay(3*speed).animate({left:'233px',width:'475'},speed).animate({top:'61 2px'},speed);
$(But[6]).delay(3*speed).animate({left:'0',width:'225'},speed).animate({top:But_Pos [5]},speed,Set_But_Array);
for (var i=1;i<6;i++) {
$(But[i]).delay(4*speed).animate({top:But_Pos[i-1]},speed)
}
Track_Img = (-1) * Track_Img;
Track_Large_Img++;
if (Track_Large_Img > (Num_But-1)) {
Track_Large_Img = 0;
}
}
</script>
</head>
<body>
<div style="position:absolute;width:100%;height:100%">
<!--- Hoofd Logo --->
<div class="divhoofdlogo">
<a href="Main_Page.html"><img class="hoofdlogo" src="Images/Logo.png"></a>
</div>
<!--- Einde Hoofd Logo --->
<div style="position:absolute;width:723px;height:708px;top:25%;left:50%;margin-left:-361.5px;">
<div class="divbutton" id="But1" style="top:0px;"><a class="buttons" href="Stoelen.html?0,0">Stoelen</a></div>
<div class="divbutton" id="But2" style="top:68px;"><a class="buttons" href="Gestoffeerde_Stoelen.html?0,0">Gestoffeerde Stoelen</a></div>
<div class="divbutton" id="But3" style="top:136px;"><a class="buttons" href="Schommelstoelen.html?0,0">Schommelstoelen</a></div>
<div class="divbutton" id="But4" style="top:204px;"><a class="buttons" href="Tuinbanken.html?0,0">Tuinbanken</a></div>
<div class="divbutton" id="But5" style="top:273px;"><a class="buttons" href="Kasten.html?0,0">Kasten</a></div>
<div class="divbutton" id="But6" style="top:340px;"><a class="buttons" href="Salontafels.html?0,0"></a>Salontafels</div>
<div class="divbutton" id="But7" style="top:408px;"><a class="buttons" href="Overig.html?0,0">Overig</a></div>
<div class="img1" id="divimg1"><img class="img1" id="imgl1" src="Images/Salontafel/Salontafel_Combi_1.jpg"></div>
<div class="img2" id="divimg2"><img class="img2" id="imgl2" src="Images/Stoel/Stoel_Alpha_1.jpg"></div>
</div>
</div>
</body>
</html>
這是CSS:
.divbutton {
position:absolute;
vertical-align:middle;
width:225px;
height:60px;
left:0px;
border:solid 2px #CCC;
text-align:center;
background-image:url(../Images/Wood.jpg);
font-family:Calibri;
font-size:24px;
font-weight:bold;
line-height:60px;
z-index:102;
}
.divhoofdlogo {
position:absolute;
left:50%;
margin-left:-259px;
width:518px;
height:140px;
}
img.hoofdlogo {
width:518px;
height:140px;
}
a.buttons {
text-decoration:none;
color:#000;
}
#divimg1 {
position:absolute;
width:456,75px;
height:600px;
left:248.25px;
display:none;
z-index:100;
}
#divimg2 {
position:absolute;
width:456,75px;
height:600px;
left:248.25px;
display:none;
z-index:99;
}
#imgl1 {
width:456,75px;
height:600px;
}
#imgl2 {
width:456,75px;
height:600px;
}
在它工作的第一個站點。但是,有時圖像閃爍,並且當時顯示的圖像的上半部分似乎消失,並且顯示另一個div(加載下一個圖像)中的圖像。我在某處讀到,可能是因爲同時發生了不同的事情,所以我試圖包括一些延遲,但找不到解決方案。希望有人可以幫助我這個..
任何人想要一個工作示例JSBin鏈接:http://jsbin.com/AbosELu/1/edit?html,css,js,output,它的工作原理,但你仍然可以看到閃爍。 –
我沒有看到閃爍。也許這取決於你正在查看的計算機的速度?此外,圖片與按鈕上的文字不匹配。 –
今天下午我會嘗試發佈一個包含實際圖片的樣本鏈接,也許你可以看到閃爍的樣子。 – user2713955