views:

26

answers:

2

I've attempting to develop a jQuery accordion, which is work ing pretty well so far considering I don't really know jQuery.

The main problem i have is if you click about quite quickly on different sections it will eventially knock the whole accordion out for a short time which wouldn't be good enough really.

I attempted to put

if ($("#accordion ul li").is(':animated')) {

around the click function but didn't seem to do anything, could anyone give me a helping hand or tell me if it is at least possible?

Also you will notice that when clicked on, the right side of the accordion shrinks a little, is this fixable or just something i'll have to put up with?

You can view what i mean here http://dev.boomeranginternet.co.uk/accordion/accordion1.asp

Thanks in advance for any help.

Regards, J.

A: 

by putting around the click function you mean like this?

    if ($("#accordion ul li").is(":animated")) { 

    } else {
        $("#accordion ul li").click(function() {
            // do animation
        }):
    }

thats the wrong way around, the click function defines an event handler. if you want your animation to only run as long as no other animation is running you must check inside your event handler e.g.

$("#accordion ul li").click(function() {
    if ($("#accordion ul li").is(":not(animated)")) { 
        // do animation
    }
}):
marc.d
Thanks for the reply.I get a syntax error at the : next to the not with this.
JBoom
@JBoom sry i missed the double quotes, the syntax should be correct now
marc.d
Thanks marc, much appreciated.
JBoom
+2  A: 

Try something like this insted:

$("#accordion ul li").click(function(){
    if ($(':animated').length) {
        return false;
    }

    //Your code goes here...
});
whaduup
Thanks very much that seemed to have done the trick!i've reuploaded the file in case your interested.Also any ideas on the slight decrease in width (you can notice it on the right hand side) while animating?Thanks again.
JBoom