phobia
Terugkerende gebruiker
- Lid geworden
- 4 sep 2006
- Berichten
- 1.777
Ik probeer met een knop een div te openen en te sluiten
openen en sluiten zijn 2 functies.
openen en sluiten zijn 2 functies.
Code:
<script type="text/javascript">
function troggle() {
var obj = document.getElementById( 'id' );
if (obj.style.visibility=='hidden') {
openen();
}
if (obj.style.visibility=='visible') {
sluiten();
}
}
var x = 500;
var y = 180;
var inc = 2;
var z = 0;
function openen() {
var obj = document.getElementById( 'id' );
obj.style.visibility='visible';
var againx, againy;
var width = parseInt(obj.style.width);
var height = parseInt(obj.style.height);
if ( width < x ) {
obj.style.width = width + inc + 'px';
againx = true;
}
if ( height < y ) {
obj.style.height = height + inc + 'px';
againy = true;
}
if ( againx || againy ) {
setTimeout ( 'openen()', 30 );
}
}
function sluiten() {
var obj = document.getElementById( 'id' );
var againx, againy;
var width = parseInt(obj.style.width);
var height = parseInt(obj.style.height);
if ( width > z ) {
obj.style.width = width - inc + 'px';
againx = true;
}
if ( height > z ) {
obj.style.height = height - inc + 'px';
againy = true;
}
if ( againx || againy ) {
setTimeout ( 'sluiten()', 30 );
}
else
{
document.getElementById( 'id' ).style.visibility='hidden';
}
}
</script>
</HEAD>
<BODY>
<h1>Div sturen leren</h1>
<form id="form" >
<input type="button" value="Show DIV" onclick="troggle()">
</form>
<div class="div" style="position: absolute; visibility: hidden; background-color: black; width: 0px; height: 0px; z-index: 1; left: 10px; top: 177px;" id="id">
</div>
</BODY>
</HTML>