NoobDev4iPhone
NoobDev4iPhone

Reputation: 5739

How to make a YouTube-like drop-down section in Javascript?

In YouTube when you click the top right button of your profile it drops a whole section on the top, moving all the content down, when you click it again, the section disappears, moving all the content back up. How do they do that?

P.S. I'm new to Javascript, so I don't even know how to search docs for this particular solution. Please be specific in description.

Thanks!

Upvotes: 0

Views: 415

Answers (1)

megakorre
megakorre

Reputation: 2223

http://jsfiddle.net/qT3Em/

unless you want to write the animation yourself (not recomended) you shuld use a libary witch comes with animations like jquery http://www.jquery.com

it commes with a function .toggle http://api.jquery.com/toggle/ that i used in the example belove

<button>A button</button>
<div style="display:none;">
 <h1>Hidden Content</h1>
</div>
<h1>Lower Content</h1>

$(function() {
 $("button").click(function() {
  $("div").toggle("slow");
 }); 
});

that will give you the effect you want

Upvotes: 2

Related Questions