Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-07-2009, 05:28 PM   PM User | #1
javascriptnooob
New to the CF scene

 
Join Date: Dec 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
javascriptnooob is an unknown quantity at this point
Need help to animate onclick drop down DIV

I'm using the below code to expand and collapse a DIV on alternative clicks


Quote:
Code:
<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

Code:
Quote:
<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

Last edited by javascriptnooob; 12-07-2009 at 05:32 PM..
javascriptnooob is offline   Reply With Quote
Old 12-07-2009, 05:34 PM   PM User | #2
gusblake
Regular Coder

 
Join Date: Jan 2006
Posts: 568
Thanks: 6
Thanked 84 Times in 84 Posts
gusblake is on a distinguished road
I think your code is OK but you're not using a timer, so the expansion of the div happens as quickly as the processor can work, which makes it look instant.
gusblake is offline   Reply With Quote
Old 12-07-2009, 05:58 PM   PM User | #3
javascriptnooob
New to the CF scene

 
Join Date: Dec 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
javascriptnooob is an unknown quantity at this point
Smile

Help me bud, show me how.
javascriptnooob is offline   Reply With Quote
Old 12-07-2009, 06:06 PM   PM User | #4
javascriptnooob
New to the CF scene

 
Join Date: Dec 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
javascriptnooob is an unknown quantity at this point
Tried this, no luck,
Quote:
Code:
function update(newheight){
document.getElementById("hidden").style.height=newheight+"px";
document.getElementById("hidden").style.display="block";
}
function show() {
var curheight=0;
var fullheight=document.getElementById("hidden").offsetHeight;
while(curheight<fullheight) {
curheight=curheight+10;
setTimeout("update(curheight)", 100);
}
}
</script>
javascriptnooob is offline   Reply With Quote
Old 12-07-2009, 11:58 PM   PM User | #5
gusblake
Regular Coder

 
Join Date: Jan 2006
Posts: 568
Thanks: 6
Thanked 84 Times in 84 Posts
gusblake is on a distinguished road
Code:
function show(id, fullheight) {
var div=document.getElementById(id);
var curheight=parseInt(div.style.height);
var newheight=curheight+10;
div.style.height=newheight+"px";
if(newheight<=fullheight) {
setTimeout("show('"+id+"',"+fullheight+")",100);
}
}

show('hidden',200) //200px
gusblake is offline   Reply With Quote
Users who have thanked gusblake for this post:
javascriptnooob (12-08-2009)
Old 12-08-2009, 04:47 AM   PM User | #6
javascriptnooob
New to the CF scene

 
Join Date: Dec 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
javascriptnooob is an unknown quantity at this point
Thank you it worked, used visibility:hidden instead of 'display'
javascriptnooob is offline   Reply With Quote
Reply

Bookmarks

Tags
display, drop down, visibility

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:02 AM.


Advertisement
Log in to turn off these ads.