javascriptnooob
12-07-2009, 05:28 PM
I'm using the below code to expand and collapse a DIV on alternative clicks
<script>
function Tog(id){
var x=document.getElementById(id);
if(x) {
if(x.style.display=='none')
{ x.style.visibility='visible';
x.style.display='block';
}
else{ x.style.visibility='hidden';
x.style.display='none';
}
}
}
</script>
<a href="#" onclick="Tog('togme')" > Click me tog 'togme'</a>
<div id="togme">
Content inside this DIv will hide and show on alternative clicks
</div>
When you click on the link div togme drops down suddenly, I need to make it slow and animated, however I'm not able to make it animated yet.
I tried playing around with the below code
<script>
function show() {
var curheight=0;
var fullheight=document.getElementById("hidden").offsetHeight;
while(curheight<fullheight) {
curheight=curheight+10;
document.getElementById("hidden").style.height=curheight+"px";
document.getElementById("hidden").style.display="block";
// SET DELAY HERE FOR EVERY INCREMENT IN VALUE OF NEW HEIGHT
}
}
</script>
<i onclick="show()" >Click me</i>
<div id='hidden' style="display:none;">
Hide me<br>
Hide me<br>
Hide me<br>
Hide me<br>
Hide me<br>
Hide me<br>
Hide me<br>
</div>
Still no luck, Something is wrong with the usage of display:block , It display whole of it in a click, Help me fix this
<script>
function Tog(id){
var x=document.getElementById(id);
if(x) {
if(x.style.display=='none')
{ x.style.visibility='visible';
x.style.display='block';
}
else{ x.style.visibility='hidden';
x.style.display='none';
}
}
}
</script>
<a href="#" onclick="Tog('togme')" > Click me tog 'togme'</a>
<div id="togme">
Content inside this DIv will hide and show on alternative clicks
</div>
When you click on the link div togme drops down suddenly, I need to make it slow and animated, however I'm not able to make it animated yet.
I tried playing around with the below code
<script>
function show() {
var curheight=0;
var fullheight=document.getElementById("hidden").offsetHeight;
while(curheight<fullheight) {
curheight=curheight+10;
document.getElementById("hidden").style.height=curheight+"px";
document.getElementById("hidden").style.display="block";
// SET DELAY HERE FOR EVERY INCREMENT IN VALUE OF NEW HEIGHT
}
}
</script>
<i onclick="show()" >Click me</i>
<div id='hidden' style="display:none;">
Hide me<br>
Hide me<br>
Hide me<br>
Hide me<br>
Hide me<br>
Hide me<br>
Hide me<br>
</div>
Still no luck, Something is wrong with the usage of display:block , It display whole of it in a click, Help me fix this