Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-16-2012, 10:50 AM   PM User | #1
resin
Regular Coder

 
Join Date: Nov 2011
Posts: 142
Thanks: 5
Thanked 0 Times in 0 Posts
resin is an unknown quantity at this point
prevent click while animating?

Hello, I have a jQuery function that executes when I click a certain element. It consists of a few fades and animations, which take a few seconds to play all the way through. How can I prevent the function from executing a second time, while those fades and animations are still going on? And whenever the fades and animations aren't going on, then I want to be able to click the element again. I guessing it's something to be placed before the .click, $('#test').?.click(function() {}); ??

Last edited by resin; 08-16-2012 at 10:53 AM..
resin is offline   Reply With Quote
Old 08-17-2012, 09:39 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Code:
var running = false;
$(function() {
    $('#test').click(function() {
        if (running == true) return;
        running = true;
        $('#test2').fadeIn(1000).delay(1000).fadeOut(1000, function () {
            running = false;
        });
    });

});
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 08-18-2012, 12:26 PM   PM User | #3
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Code:
if (running == true) return false;
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 08-19-2012, 08:13 AM   PM User | #4
resin
Regular Coder

 
Join Date: Nov 2011
Posts: 142
Thanks: 5
Thanked 0 Times in 0 Posts
resin is an unknown quantity at this point
What would you do for functions that call multiple selectors, which finish at different times? For example-

Code:
$('#test').click(function() {
$('#test2').fadeIn(1000).delay(1000).fadeOut(1000);
$('#test3').delay(500).fadeOut(300);
$('#test4').animate({"top": "-150px"}, 15000);
});
How can I make it so nothing inside this function executes again, until all actions have fully completed?
resin is offline   Reply With Quote
Old 08-19-2012, 12:04 PM   PM User | #5
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
@resin. You've deleted your recent posts. This makes it difficult for others to follow, and to understand what question my recent post was answering.

It is best not to delete posts that have already been responded to.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 01:09 PM.


Advertisement
Log in to turn off these ads.