in Education by
I have this bit of javascript written with jQuery 1.2.5. It's contained inside the main function() of a plugin that I wrote. The plugin is a horizontal gallery scroller very similar to jCarousel. It does alot of auto calculating of widths and determines how many to scroll based on that and the size of the images, which is what all the calculations are that are going on. What my question is, how do I prevent this from firing off before a previous execution is finished. For instance, if I get a little click happy and just frantically mash down on .digi_next. Things don't go so well in the UI when that happens and I'd like to fix it :) I thought the answer might lie in queue, but all my attempts at using it haven't turned out anything worthwhile. var self = this; $(".digi_next", this.container).click(function(){ var curLeft = $(".digi_container", self.container).css("left").split("px")[0]; var newLeft = (curLeft*1) - (self.containerPad + self.containerWidth) * self.show_photos; if (newLeft < ((self.digi_gal_width - (self.containerPad + self.containerWidth) * self.show_photos)) * -1) { newLeft = ((self.digi_gal_width - (self.containerPad + self.containerWidth) * self.show_photos)) * -1; } $(".digi_container", self.container).animate({ left: newLeft + "px" }, self.rotateSpeed); }); JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Just use a global busy flag. When you enter your click handler, check it, and only proceed if it's false. Immediately set it to true, and then set it back to false when the animation ends. JavaScript is single-threaded, so there is no race condition to worry about. var busy = false; $("...").onclick(function() { if (busy) return false; busy = true; $("...").animate(..., ..., ..., function() { busy= false; }); return false; });

Related questions

0 votes
    I have this bit of javascript written with jQuery 1.2.5. It's contained inside the main function( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Since I can't intercept action_down event for gridview, I would like to get (x,y) coordinate of ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 30, 2022 in Education by JackTerrance
0 votes
    I want to change the images in image view on Onclick function. I have already tried this: bt_audiocapture. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 23, 2022 in Education by JackTerrance
0 votes
    I'm attempting to automate a payment system, where the "Pay with PayPal" button is within an iFrame. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I'm a bit surprised I'm having trouble finding this online, but I can't seem to find an example ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I'm a bit surprised I'm having trouble finding this online, but I can't seem to find an example ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I'm a bit surprised I'm having trouble finding this online, but I can't seem to find an example ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Here's a code snippet. . . Yes No Clearly, what I'm trying to do is call the routine linked to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I have one aspx page with 1000 anchor tag. I want to open single popup onclick of anchor tag & ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 20, 2022 in Education by JackTerrance
0 votes
    I have a table like below 11 12 13 11 12 13 11 12 13 After I click on the table, I ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have a table like below 11 12 13 11 12 13 11 12 13 After I click on the table, I ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Based on Raphael demo: http://raphaeljs.com/australia.html I have created objects that changes their colour. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    ________ are a set of rules that determine the execution of a transaction. A. Program B. Instruction C. Tables D. Contracts...
asked Feb 23, 2023 in Technology by JackTerrance
0 votes
    I got this question regarding web server (such as nginx, Cherokee or Oracle iPlanet) and Java containers ( ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Aug 1, 2022 in Education by JackTerrance
0 votes
    I have a web page that accepts an excel file, reads data from it and stores it in a buffer table ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 30, 2022 in Education by JackTerrance
...