Results 1 to 8 of 8

Thread: Help with ontoggle event handler? - Animated Collapse

  1. #1
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help with ontoggle event handler? - Animated Collapse

    1) Script Title: Animated Collapse

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...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!
    Last edited by piers; 07-10-2009 at 07:51 AM.

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Try something like the below ontoggle code:

    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.
    DD Admin

  3. The Following User Says Thank You to ddadmin For This Useful Post:

    piers (07-11-2009)

  4. #3
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    right on! thanks

  5. #4
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    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?

  6. #5
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Ops, a nesting problem. Try this instead:

    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
    	}
    }
    DD Admin

  7. #6
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    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!

  8. #7
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    You can simply test for oneisopen (without the "!" in front) for that:

    Code:
    	if (oneisopen){
    		//do something
    	}
    DD Admin

  9. The Following User Says Thank You to ddadmin For This Useful Post:

    piers (07-11-2009)

  10. #8
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Done.

    thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •