2011-10-08 31 views
0

我用HTML格式绘制了一个图像在div框外。我对JavaScript不太流利,我试图像建筑图像一样显示一个div。什么是一个很好的JavaScript公式来显示每个div一次,而不用重写我的代码?如果这能让事情变得更容易,我可以访问Dreamweaver。这里是我的一小块图片:JavaScript编码一次显示一格div

<html> 
<head> 

<style type="text/css"> 

</head> 

#apDiv6101 { 
position:absolute; 
width:131px; 
height:81px; 
z-index:35; 
left:119px; 
top:785px; 
background-color:#80d010;} 

#apDiv6102 { 
position:absolute; 
width:9px; 
height:8px; 
z-index:45; 
left:119px; 
top:858px; 
background-color:#80d010;} 

#apDiv6104 { 
position:absolute; 
width:9px; 
height:8px; 
z-index:45; 
left:241px; 
top:858px; 
background-color:#80d010;} 

#apDiv6106 { 
position:absolute; 
width:9px; 
height:8px; 
z-index:45; 
left:241px; 
top:785px; 
background-color:#80d010;} 

#apDiv6108 { 
position:absolute; 
width:9px; 
height:8px; 
z-index:45; 
left:119px; 
top:785px; 
background-color:#80d010;} 

#apDiv6110 { 
position:absolute; 
width:121px; 
height:73px; 
z-index:40; 
left:124px; 
top:789px; 
background-color:#000000;} 


</style> 

<body bgcolor="#000000"> 

<div id="apDiv6110"></div> 
<div id="apDiv6108"></div> 
<div id="apDiv6106"></div> 
<div id="apDiv6104"></div> 
<div id="apDiv6102"></div> 
<div id="apDiv6101"></div> 

</body> 
</html> 
+0

JavaScript是**非常不同**从Java。 –

+0

你的问题似乎是关于JavaScript,而不是Java。这是两种完全不同的语言。 –

+0

正如其他人所说的,Java和Javascript实际上是非常不同的东西,我可能会建议您使用Google“Java vs Javascript”,然后开始查看http://jquery.com/以实现您想要的功能。 – Ankur

回答

0

据我了解,你想图像出现一个接一个。 并且你只想要一个图像立即出现(隐藏前一个图像)

这将是代码。

(假设jQuery是使用)

var img_arr = ['appDiv6101','appDiv6102'....,'appDiv6110'];

var i =0; 
function cycleImages(){ 
// hide all the divs 
$('div#^appDiv').hide(); 
//now show the apppropiate div 
i = i++ % 12; 
$('div#'+img_arr[i-1]).show(); 
// wait for sometime and call again. 
setTimeout(cycleImages,30); 
} 
1

在该页面隐藏所有的div,然后逐步地,直到在文档中的所有div显示在一个时间显示一个。

http://jsfiddle.net/fFtZc/2/

的JS代码:

var current = 0, L, alldivs; 

function displayOne() { 
    if (current < L) { 
     alldivs[current].style.display = ''; 
     current++; 
     setTimeout(displayOne, 750); 
    } 
} 

function init() { 
    var i; 
    alldivs = document.getElementsByTagName('div'); 
    for (i=0, L=alldivs.length; i<L; i++) { 
     alldivs[i].style.display='none'; 
    } 
    setTimeout(displayOne, 750); 
} 

if (document.addEventListener) { 
    document.addEventListener("DOMContentLoaded", init, false); 
} 
else { 
    /* for other browsers */ 
    window.onload = init; 
} 
+0

谢谢Cheeso, 我把你的建议放在标签中,但我认为我称它为错。 – jackmeister

+0

您可以查看jsfiddle网址中的代码 - 如何调用它非常清晰地显示在那里。 – Cheeso