Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Problem with delay() method in jQuery
Old 04-08-2010, 10:51 AM Problem with delay() method in jQuery
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
Just posted this thread a few mins ago and for some reason it got deleted? Maybe it was because of the URL shortening I used.

Anyway here is an example of what I mean
http://www.mattpealing.co.uk/concept/simplesubmission/

I can't get each stage of the animation to execute in the order that I want, here is the code I'm using:
Code:
    1.    // content accordion
    2.    $(document).ready(function(){
    3.    lastBlock = $("#a1");
    4.    maxWidth = 290;
    5.    minWidth = 145;
    6.    $("#slide li a").click(
    7.    function(){
    8.    if($(this).attr('class') != 'active') {
    9.    $('#slide .active').removeClass('active');
    10.    $('#slide li .content').fadeOut(500);
    11.    $('#slide li .num').fadeIn(500);
    12.    
    13.    $(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:400 });
    14.    $(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
    15.    lastBlock = this;
    16.    
    17.    $(this).addClass('active');
    18.    $('#slide .active .num').fadeOut(500);
    19.    $('#slide .active .content').fadeIn(500);
    20.    }
    21.    });
});
Lines 13 to 15 deal with the actual 'accordion' part of the animation. I want it so that the animation goes in the following order:
1. User clicks an unopened coloured box
2. The content in the currently open box fades out
3. The large number in the currently open box fades in
4. The accordion animates so that the open box closes, and the newly selected box opens
5. The large number fades out
6. The new content fades in
But it seems like a lot of these are happening simultaneously, I want it so that they happen one after the other.

I've tried using the new 'delay' method, but the accordion part of the script just seems to ignore it! I've also tried using callback's to bind a function so that it executes when the previous function has finished executing, but it seemed to mess things up as the '$(this)' variable seemed to get overwritten by the nested functions... if that makes sense?

Does anyone know what the best approach is?

Here is what I've tried by using 'delays', but the animation happens as soon as the box has been clicked for some reason!

Code:
    1.            function(){
    2.                if($(this).attr('class') != 'active') {
    3.                    $('#slide .active').removeClass('active');
    4.                    $('#slide li .content').fadeOut(500).delay(1000);
    5.                    $('#slide li .num').fadeIn(500).delay(1000);
    6.                   
    7.                    $(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:400 }).delay(1000);
    8.                    $(this).animate({width: maxWidth+"px"}, { queue:false, duration:400}).delay(1000);
    9.                    lastBlock = this;
    10.                   
    11.                    $(this).addClass('active');
    12.                    $('#slide .active .num').fadeOut(500);
    13.                    $('#slide .active .content').fadeIn(500);
    14.                }
    15.        });
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Reply     « Reply to Problem with delay() method in jQuery
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.08175 seconds with 12 queries