2013-08-24 75 views
1

我刚刚开始使用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(加载下一个图像)中的图像。我在某处读到,可能是因为同时发生了不同的事情,所以我试图包括一些延迟,但找不到解决方案。希望有人可以帮助我这个..

+0

任何人想要一个工作示例JSBin链接:http://jsbin.com/AbosELu/1/edit?html,css,js,output,它的工作原理,但你仍然可以看到闪烁。 –

+0

我没有看到闪烁。也许这取决于你正在查看的计算机的速度?此外,图片与按钮上的文字不匹配。 –

+0

今天下午我会尝试发布一个包含实际图片的样本链接,也许你可以看到闪烁的样子。 – user2713955

回答

1

我想我发现了代码的问题,并修复它。请让我知道,如果你认为它可能确实是这个问题,答案是正确的..

如果你看一下不同的动画的时候,你可以看到一个循环需要:

5*speed 

动画将两张图片/两个div对齐。但为了多次滑动某些东西,您必须将它滑入其间。当div/image的z-index低于当时显示的div/image时,我想在幕后很快做到这一点。所以,当一幅图像完全滑落时,图像后面的另一幅图像会很快滑落。然而,这是后:

5*speed 

在代码:

$('#divimg1').delay(5*speed).slideUp(10); 

所以

slideUp(10); 

部分在新的循环是实际发生。该循环通过反转z-索引开始,从而将正面向上滑动0.01秒的图像。这就是为什么它看起来只有图像的上半部分闪烁。我想这就是问题所在。

解决的办法很简单,我认为..只是延缓z-index的变化,直到效果基本show后:

setTimeout(function() { 
    $('.img2').css('z-index','101'); 
    $('.img1').css('z-index','99'); 
}, 150); 

该解决方案似乎工作:它没有闪烁3-4轮! 感谢您对我的问题的回应!