
Home
Dynamic Content
Here
|
Categories
Partners
DaniWeb is an exciting community for web developers, Internet marketers, and technology enthusiasts.
Other Sections
Compatibility
|
|
NS6+ IE5+ Opera 7+
Animated Collapsible DIV Author:
Note: Last updated June 27th, 07'. Added ability for a DIV to be initially expanded. Description: This script collapses any DIV on the page and lets users manually toggle its appearance via a smooth "Web 2.0 style" animation. It's a popular effect on social networking/ comment sites such as Digg. Three distinguishing features of this script are:
Have fun sliding content up and down! Demos: Example 1: Slide Down || Slide UpContent inside DIV!Note: CSS height attribute definedExample 2: Show/ Hide ContentContent inside DIV!Content inside DIV!Note: No CSS height attribute defined. Persistence enabled.Step 1: Insert the following code in the HEAD section of your page Notice the code at the very top- a doctype declaration. Your page must contain one of the valid doctypes in order for this script to work correctly! The code above also references an external .js file, which you can download below (right click/ select "Save As"): Step 2: Insert the below sample code into the BODY section of your page: And there you have it. Read on for more detailed instructions. Setup InformationThe links to expand and contract the DIV, and the arbitrary DIV itself, look like this: <a href="javascript:collapse1.slidedown()">Slide
Down</a> | <a href="javascript:collapse1.slideup()">Slide
Up</a> Then, following the DIV to expand/contact, you need to call a function to finalize the effect with the desired settings: <script type="text/javascript"> " By default the script will dynamically collapse the DIV in
question when the page loads. You can optionally specify that the script leave
the DIV expanded instead, by making use of the 4th optional parameter of var collapse1=new animatedcollapse("dog", 1000, false, "block") Available functionsThe script supports 3 functions you can invoke inside your links to toggle the display of the target DIV:
Considerations when defining your DIVThis script will work on both DIVs with an explicit CSS " <!--DIV with height defined --> The advantage of a DIV with a height attribute explicitly defined is that the user can expand/contract the DIV almost immediately, instead of after the document has fully loaded (when the script can dynamically get its height). Of course, in real life, you often cannot set the DIV's height in advanced for various reasons, and this script will still work in these cases. Another thing to take note is if you wish to add padding/margins to the DIV- you'll need to do it inside another DIV contained within it instead, for example: <div id="cat" style="width: 300px;"> In other words, the "
|