Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

division styles... 1

Status
Not open for further replies.

mackey333

Technical User
May 10, 2001
563
US
I am using a bunch of divisons to make a slide show...I can get them to hide ok by changing the visiblity hidden, but how do I show the hidden div?...I tried the logical thing (change the visiblity to visible) but that didn't work...what is the propert name to show it?
 
All those things should work - and display:none is particularly good when you don't want scrollbars to appear - if the hidden element is large and/or placed at bottom of page.

If they are not working you must be leaving somthing out when you try to change them, are you sure to use style? perhaps post your show/hide function.
b2 - benbiddington@surf4nix.com
 
ok here is a segment of the function and code:

Code:
<script language=&quot;javascript&quot;>

     function timeout() {

     setTimeout('doChange', 2000)

}

function doChange() {

	document.getElementById('DivImg1').style.visibility = 'hidden';

	[b]document.getElementById('DivImg2').style.visibility = 'none';[/b]

}
</script>
</head>

<body bgColor=&quot;FF0000&quot; onLoad=&quot;timeout()&quot;>

<div align=&quot;center&quot; id=&quot;testDiv1&quot; style=&quot;position: relative; background-color: #FFFFFF;  height: 100%; width: 100%&quot;> 

	<table align=&quot;center&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;100%&quot; height=&quot;100%&quot;>
	
	     <tr>
		
	          <td>
            
                       <div align=&quot;center&quot; id=&quot;testImg1&quot;>
            
            	            <img border=&quot;0&quot; src=&quot;testPic.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
                      </div>

                      <div align=&quot;center&quot; id=&quot;DivImg2&quot; style: hidden>
            
            	           <img border=&quot;0&quot; src=&quot;testPic.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
                           </div>
                      </td>
		
		</tr>
		
	</table>
		
</div>
		
		
</body>
 
hmm..for some reason that didn't turn bold... don't mind the bold tags...hmm...
 
First of all - the setTimeout piece is not calling anything, you have to specify a function:

function timeout() {
setTimeout('doChange()', 2000)
}

Also - the &quot;none&quot; option is for display - not visibility.
function doChange() {

document.getElementById('DivImg1').style.visibility = 'hidden';

document.getElementById('DivImg1').style.display='none'

}


But I thought you were having trouble showing it again? Try this function if you like - it has a toggle switch, so every time you click the button or whatever - it will either hide or show - depending what it did last time.
var show = true;
function doChange() {
if(!show){
document.getElementById('DivImg1').style.visibility = 'hidden';
document.getElementById('DivImg1').style.display = 'none'
}
else{
document.getElementById('DivImg1').style.visibility = 'visible';
document.getElementById('DivImg1').style.display = 'block'
}
show =(show)?false:true;
}


Also visibility=&quot;show&quot; is Netscape's lame idea.
b2 - benbiddington@surf4nix.com
 
what do you mean the timeout isn't calling anything, you just rewrote what I had, also this is an automatic thing thats why the time out is there, there is more, I just didn't put every function down...ok I will try it with the different code when I get a chance..thanx
 
ok..here is the whole code:

Code:
<html>

<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>

<title>test</title>

<script language=&quot;javascript&quot;>

function timeout() {

	setTimeout('doChange1()', 3000);
}

function doChange1() {


	document.getElementById('testDivImg1').style.visibility = 'hidden';

	document.getElementById('testDivImg2').style.display = 'none';

	setTimeout('doChange2()', 1000)
}

function doChange2() {

	document.getElementById('testDivImg2').style.visibility = 'hidden';

	document.getElementById('testDivImg3').style.display = 'none';

	setTimeout('doChange3()', 1000)
}

function doChange3() {

	document.getElementById('testDivImg3').style.visibility = 'hidden';

	document.getElementById('testDivImg4').style.display = 'none';
	
	setTimeout('doChange4()', 1000)
}

function doChange4() {

	document.getElementById('testDivImg4').style.visibility = 'hidden';

	document.getElementById('testDivImg5').style.display = 'none';

	setTimeout('doChange5()', 1000)
}

function doChange5() {

	document.getElementById('testDivImg5').style.visibility = 'hidden';

	document.getElementById('testDivImg6').style.display = 'none';

}



</script>

</head>

<body bgColor=&quot;FF0000&quot; onLoad=&quot;timeout()&quot;>

<div align=&quot;center&quot; id=&quot;testDiv1&quot; style=&quot;position: relative background-color: #FFFFFF;  height: 100%; width: 100%&quot;> 

	<table align=&quot;center&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;100%&quot; height=&quot;100%&quot;>
	
		<tr>
		
			<td>
            
            <div align=&quot;center&quot; id=&quot;testDivImg1&quot; style=&quot;position: absolute&quot;>            
            	<img border=&quot;0&quot; src=&quot;testPic1.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
            </div>

            <div align=&quot;center&quot; id=&quot;testDivImg2&quot; style=&quot;position: absolute; visibility: hidden&quot;>
            
            	<img border=&quot;0&quot; src=&quot;testPic2.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
            </div>
            
            <div align=&quot;center&quot; id=&quot;testDivImg3&quot; style=&quot;position: absolute; visibility: hidden&quot;>
            
            	<img border=&quot;0&quot; src=&quot;testPic3.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
            </div>
            
            <div align=&quot;center&quot; id=&quot;testDivImg4&quot; style=&quot;position: absolute; visibility: hidden&quot;>
            
            	<img border=&quot;0&quot; src=&quot;testPic4.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
            </div>
            
            <div align=&quot;center&quot; id=&quot;testDivImg5&quot; style=&quot;position: absolute; visibility: hidden&quot;>
            
            	<img border=&quot;0&quot; src=&quot;testPic5.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
            </div>
            
            <div align=&quot;center&quot; id=&quot;testDivImg6&quot; style=&quot;position: absolute; visibility: hidden&quot;>
            
            	<img border=&quot;0&quot; src=&quot;testPic6.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
            </div>
      
			</td>
		
		</tr>
		
	</table>
		
</div>
</body>
</html>

the first img shows up and goes away fine but the others won't show..what did I do now?...i'm starting to get mad now..nothing can be easy..any ideas?
 
No, all I meant was you had missed the brackets from the function call in timeout - and that it wasn't doing anything. I am pretty sure it is possible to simplify all those functions into one - hold on ;-)
b2 - benbiddington@surf4nix.com
 
I know it is..it was easier to copy and paste for some makeshift code, I just need to know why the hide/show doesn't work.

-Greg
 
Actually. setTimeout is very annoying to work with, because they are all set at the start - so the way you have done it is one of the only ways to do it, rather than a complex for loop requiring consistent div names etc. (or write a sleep function)

The hiding is working for me. Ohhhh, wait, I see, you have some of your divs hidden - and thsoe ar the ones you are showing - why are you using display:none? Am I right by thinking that in the function below you want to show
testDivImg2? Because at the moment you are hiding it as well as TestDivImg1 - so change it visibility = &quot;visible&quot;, instead of display - my apologies, a crossed wire has occured!


function doChange1() {
document.getElementById('testDivImg1').style.visibility = 'hidden';

document.getElementById('testDivImg2').style.display = 'none';

setTimeout('doChange2()', 1000)
}

Otherwise, the way you are doing it is the most straight forward that I can see.
b2 - benbiddington@surf4nix.com
 
each function is supposed to hide the one that is showing and then show the next one...everything hides fine but doesn't show..do you think maybe it's being overrided by the hidden param. in the div's..should I make them hidden with javascript maybe?
 
ok..now I'm really confused... here is the code...

Code:
<html>

<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>
<title>test page...</title>

<script language=&quot;javascript&quot;>

function timeout() {

	if (document.getElementById) {  
		
		document.getElementById('testDivImg2').style.visiblity = 'hidden';
		document.getElementById('testDivImg3').style.visiblity = 'hidden';
		document.getElementById('testDivImg4').style.visiblity = 'hidden';
		document.getElementById('testDivImg5').style.visiblity = 'hidden';
		document.getElementById('testDivImg6').style.visiblity = 'hidden';		
	
	}    
		
	//alert(document.getElementById('testDivImg3').style.visiblity)

	setTimeout('doChange1()', 3000);
}

function doChange1() {


	document.getElementById('testDivImg1').style.visibility = 'hidden';

	document.getElementById('testDivImg2').style.display = 'none';

      //alert(&quot;doChange1:  td1 &quot; + document.getElementById('testDivImg1').style.visibilty + &quot; td2&quot; + document.getElementById('testDivImg2').style.display)

	setTimeout('doChange2()', 1000)
}

function doChange2() {

	document.getElementById('testDivImg2').style.visibility = 'hidden';

	document.getElementById('testDivImg3').style.display = 'none';

      //alert(&quot;doChange2:  td2 &quot; + document.getElementById('testDivImg2').style.visibilty + &quot; td3 &quot; + document.getElementByID('testDivImg3').style.display)

	setTimeout('doChange3()', 1000)
}

function doChange3() {

	document.getElementById('testDivImg3').style.visibility = 'hidden';

	document.getElementById('testDivImg4').style.display = 'none';
	
      //alert(&quot;doChange3:  td4 &quot; + document.getElementById('testDivImg2').style.visibilty + &quot; td4 &quot; + document.getElementByID('testDivImg3').style.display)

	setTimeout('doChange4()', 1000)
}

function doChange4() {

	document.getElementById('testDivImg4').style.visibility = 'hidden';

	document.getElementById('testDivImg5').style.display = 'none';

      //alert(&quot;doChange4:  td4 &quot; + document.getElementById('testDivImg2').style.visibilty + &quot; td5 &quot; + document.getElementByID('testDivImg3').style.display)

	setTimeout('doChange5()', 1000)
}

function doChange5() {

	document.getElementById('testDivImg5').style.visibility = 'hidden';

	document.getElementById('testDivImg6').style.display = 'none';

      //alert(&quot;doChange5:  td5 &quot; + document.getElementById('testDivImg2').style.visibilty + &quot; td6 &quot; + document.getElementByID('testDivImg3').style.display)

}



</script>

</head>

<body bgColor=&quot;FF0000&quot; onLoad=&quot;timeout()&quot;>

<div align=&quot;center&quot; id=&quot;testDiv1&quot; style=&quot;position: relative background-color: #FFFFFF;  height: 100%; width: 100%&quot;> 

	<table align=&quot;center&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;100%&quot; height=&quot;100%&quot;>
	
		<tr>
		
			<td>
            
            <div align=&quot;center&quot; id=&quot;testDivImg1&quot; style=&quot;position: absolute&quot;>            
            	
            	<img border=&quot;0&quot; src=&quot;testPic1.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
            </div>

            <div align=&quot;center&quot; id=&quot;testDivImg2&quot; style=&quot;position: absolute&quot;>
            
            	<img border=&quot;0&quot; src=&quot;testPic2.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
            </div>
            
            <div align=&quot;center&quot; id=&quot;testDivImg3&quot; style=&quot;position: absolute&quot;>
            
            	<img border=&quot;0&quot; src=&quot;testPic3.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
            </div>
            
            <div align=&quot;center&quot; id=&quot;testDivImg4&quot; style=&quot;position: absolute&quot;>
            
            	<img border=&quot;0&quot; src=&quot;testPic4.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
            </div>
            
            <div align=&quot;center&quot; id=&quot;testDivImg5&quot; style=&quot;position: absolute&quot;>
            
            	<img border=&quot;0&quot; src=&quot;testPic5.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
            </div>
            
            <div align=&quot;center&quot; id=&quot;testDivImg6&quot; style=&quot;position: absolute&quot;>
            
            	<img border=&quot;0&quot; src=&quot;testPic6.gif&quot; width=&quot;24&quot; height=&quot;69&quot;>
            
            </div>
      
			</td>
		
		</tr>
		
	</table>
		
</div>
		
		
</body>

</html>

for some reason everything shows up (doesn't hide) and then as it goes through the functions they disapear one at a time..what is going on?!?
 
Well display:none says to the browser, effectively the element isn't there - don't even allow space for it. I think in the designation of your div's, you should set their visibility to hidden - Oh, you just have a spelling error in visibility - correct that in the function timeout, then modify your your show/hide functins to be like:

function doChange1() {
document.getElementById('testDivImg1').style.visibility = 'hidden';

document.getElementById('testDivImg2').style.visibility = 'visible';

setTimeout('doChange2()', 1000)
}


So this function hides testDivImg1 - and then shows testDivImg2, this is what you mean aye? (No I'm not Canadian)

b2 - benbiddington@surf4nix.com
 
darn...I looked back over the code I misspelled visibility and almost the whole this was copied and pasted it just carried over..thanks for the help though...why are error messages so uninformitive?...

-Greg
 
HELLO
i want to put a div align tab around a table so that i can move a table with co-ords but i dont know how to do this!! can some1 plz help??
 
kaneus,
have you tryed just pasting your table code inside <div> tag? :) Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top