PDA

View Full Version : Help with ontoggle event handler? - Animated Collapse



piers
07-10-2009, 06:38 AM
1) Script Title: Animated Collapse

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/animatedcollapse_suppliment.htm

3) Describe problem:

I'm trying to use the ontoggle($, divobj, state) event handler to fade out a div (outside the collapsible divs) that has an embedded QT movie.

Basically I would like the div to fade to 'hidden' when ALL the animated divs are in a collapsed state. I am showing the div via an onclick event within the collapsible divs (so that's no problem), but I can't figure out how to fade it out...

any help would be much appreciated!

ddadmin
07-11-2009, 02:53 AM
Try something like the below ontoggle code:


animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted
var oneisopen=false
$.each(animatedcollapse.divholders, function(){
if (this.$divref.css('display')!='none'){
oneisopen=true
}
if (!oneisopen){
//do something
}
})
}

It basically will only execute "do something" when all the animated DIVs on the page are collapsed. Replace that line with the desired code to execute.

piers
07-11-2009, 03:56 AM
right on! thanks

piers
07-11-2009, 04:38 AM
Ummm... it seems that this code executes 'do something' when any div is collapsed (on toggle), rather then when ALL the divs are in a collapsed state...

but perhaps I'm missing something?

ddadmin
07-11-2009, 05:33 AM
Ops, a nesting problem. Try this instead:


animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted
var oneisopen=false
$.each(animatedcollapse.divholders, function(){
if (this.$divref.css('display')!='none'){
oneisopen=true
}
})
if (!oneisopen){
//do something
}
}

piers
07-11-2009, 06:00 AM
That works beautifully, thanks!

Of course, now I'm wondering if there's a way to add an oppositional function - in other words when ANY div is opened: 'do something'

Thanks for your time.. much appreciated!

ddadmin
07-11-2009, 06:18 AM
You can simply test for oneisopen (without the "!" in front) for that:


if (oneisopen){
//do something
}

piers
07-11-2009, 06:42 AM
Done.

thanks :)