
Home
Dynamic Content
Here
|
Categories
Partners
DaniWeb is an exciting community for web developers, Internet marketers, and technology enthusiasts.
Other Sections
Sweet Ads
Compatibility
|
|
FF1+ IE6+ Opera 9+
Animated Collapsible DIV v2.01 Author:
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 many social networking/ comment sites. Three distinguishing features of this script are:
Have fun sliding content up and down! Demos:
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 references two external .js files, 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, plus the arbitrary DIV itself, look like this: <a
href="javascript:animatedcollapse.toggle('jason')">Toggle
Display</a> | <a href="javascript:animatedcollapse.show('jason')">Slide
Down</a> | <a href="javascript:animatedcollapse.hide('jason')">Slide
Up</a> In the HEAD section of your page, call <script type="text/javascript"> The first parameter in
|
| Attribute | Description |
fade=1/0Defaults to 0. |
Set to 0 to disable fade effect. Set to 1 to enable. |
speed=millisecondsDefaults to 500. |
Set to an integer in milliseconds to control the duration of the sliding effect (ie: 1000=1 second). |
hide=1/0Defaults to undefined. |
Set to 0 to explicitly show this DIV when the
page first loads. Set to 1 to
hide. Typically you would leave out
this attribute altogether (so it's undefined) to let the DIV default to
its default visibility based on the relevant inline or global CSS on
your page. This attribute is meant to provide an alternate way for you to define the DIV's visibility programmically when you can't or don't wish to do so via CSS. |
persist=1/0Defaults to 0. |
Set to 0 to disable persistence of this DIV's
state within browser session. Set to 1 to enable. In grouped contents,
enabling |
height=400pxDefaults to undefined. |
Set to an integer plus "px" to explicitly define
the height of the DIV using the script. Typically you would
leave out
this attribute altogether (so it's undefined) to let the DIV default to its natural height,
or that specified in either your inline or global CSS. This attribute is meant to provide an alternate way for you to define the DIV's height programmically when you can't or don't wish to do so via CSS. |
group=groupnameDefaults to undefined. |
Specifies the group this content belongs to
(if any). Contents sharing the same group name are tied together in that
only one content will be/ can be open at any time. If you wish
to enable persistence or a group of contents, you only need to enable
animatedcollapse.addDiv('cat',
'speed=400,group=pets,hide=1') The above has the same effect as enabling |
As mentioned, all attributes above are optional when calling
animatedcollapse.addDiv(). While setting some attributes to 0 usually has
the same effect as not defining it at all, the exception are "hide"
and "height". Not setting these two attributes means the script
will not modify the DIV's natural visibility and height, respectively, which is
different from setting them. Take for example:
animatedcollapse.addDiv('cat')
animatedcollapse.addDiv('dog', 'height=300px')
animatedcollapse.addDiv('rabbit', 'hide=1')
cat" DIV's visibility will be based on whether any
global or inline CSS on your page hides the DIV (using "display:none").
The DIV's height will be based on either the content's natural height, or if
CSS is defined, the CSS "height" property.dog" DIV's visibility will be based on whether any
global or inline CSS on your page hides the DIV (using "display:none").
The DIV's height will be set to 300px.rabbit" DIV's visibility will be hidden. The DIV's
height will be based on either the content's natural height, or if CSS is
defined, the CSS "height" property.The script supports 3 functions you can invoke inside your links or elsewhere to toggle the display of each collapsible DIV:
| Attribute | Description |
animatedcollapse.show(divids) |
Expands and reveals a collapsible DIV or
multiple DIVs. Enter either the ID of a single DIV (string), or an array
of multiple collapsible DIVs ids ['divid1','divid2',etc].
For example:<a href="javascript:animatedcollapse.show('jason')">Show Jason DIV</a> <a href="javascript:animatedcollapse.show(['jason', 'kelly'])">Show Jason and Kelly DIVs</a>
|
animatedcollapse.hide(divids) |
Contracts and hides a collapsible DIV or
multiple DIVs. Either enter the ID of a single DIV (string), or an array
of multiple collapsible DIVs ids. For example: <a href="javascript:animatedcollapse.hide('jason')">Show Jason DIV</a> <a href="javascript:animatedcollapse.hide(['jason', 'kelly'])">Show Jason and Kelly DIVs</a>
|
animatedcollapse.toggle(divid) |
Expand or contracts a collapsible DIV
automatically based on its inverse state. Enter the ID of a single DIV
to toggle its state. For example: <a href="javascript:animatedcollapse.toggle('jason')">Show/ Hide Jason DIV</a>
|
When the page first loads, there are two ways to initially hide those collapsible DIVs that you want hidden by default: either via normal CSS, or via the script. An example of the former first:
<div id="jason" style="width: 300px; background:
#FFFFCC; display:none">
<b>Content inside DIV!</b><br />
<b>Note: Fade effect enabled. Height programmically defined. DIV hidden using
inline CSS.</b><br />
</div>
The advantage of using regular CSS is that the DIV will be hidden from the very start, even before the script is initialized. The disadvantage is the accessibility issue for people with JavaScript disabled.
The other way to hide your DIVs is by defining the attribute "hide=1"
inside animatedcollapse.addDiv() when initializing the script:
animatedcollapse.addDiv('rabbit', 'hide=1')
The advantages with this are arguably ease of maintenance and increased accessibility. The disadvantage is that the DIV will be temporarily visible before the script is initialized and run.