How can I deactivate clicking while a function is being run?
I basically want to
not let the function do anything else if something is animating. If someone clicks too often is messes up some animation I have, because the position of the last clicked element gets changed to an element it doesn't belong to.
Is there a way to set a flag if the click function is running, move the animation code into its own function, and not allow the animation to run if that flag is true? Or maybe this is a bad way to go.
I just need to make it safe to click around, so that it doesn't mess up the saved positioning (and thus the animation) when this click function is running.
Thank you.
- $(".clsStartUpNode").click(function() {
- $lastClickedNode = $(this);
- $divID = $(this).attr("id"); // get the attr id inside the div
- $nodeID = $(this).attr("nodeID"); // get the nodeID inside the div
- $nodeLayerNumber = $(this).attr("nodeLayer");
- $nodeTitle = $(this).html();// get the whole div in html format
- CurrentLayer = $nodeLayerNumber; //assign the current layer number to CurrentLayer
- $nodePosition = $(this).position(); // position = { left: xx, top: xx}
- //animate main node, clicked node,and mode in child nodes
- if ($divID != "StartUpMainNode") {
- // set second node data in the breadcrumb
- $("#NodeTwo").attr("nodeID", $nodeID); // replace $nodeID into "nodeID"
- $("#NodeTwo").attr("nodeLayer", $nodeLayerNumber);
- $("#NodeTwo").html("<a nohref alt='" + $nodeTitle + "' title='" + $nodeTitle + "'>" + $nodeTitle + "</a>"); // to show the pointer, used <a> tag
- if ($nodeLayerNumber < 4) {
- $CircleNodesLeftPosition = $CircleNodesStartLeftPosition + (($nodeLayerNumber - 1) * 150); // used to calculate the pisition
- $("#CircleNodes").css("left", $CircleNodesLeftPosition + "px");
- }
- $("#StartUpPosition div").not("#StartUpMainNode, #" + $divID).fadeOut(300);
- $("#StartUpMainNode").stop().animate( {left:22}, function() {
- $("#StartUpMainNode").hide();
- $("#NodeMain").show();
- });
- $("#" + $divID).stop().animate( {left:152, top: 145}, function() {
- $("#" + $divID).hide();
- $("#NodeTwo").show();
- });
- setTimeout("$('.clsNodeConnector').fadeIn(300)", 250);
- //$(".clsNodeConnector").fadeIn(300); //fade in all of their connectors
- setTimeout("$.displaySubNodes($nodeID, 1)", 250);
- // $.displaySubNodes($nodeID, 1);
- }
- });
- //when main node is clicked, to go "back", animate it back into place, animate the clicked node to its original place
- $("#NodeMain").stop().click(function() {
- $("#StartUpMainNode").show();
- $("#StartUpMainNode").stop().animate({ left: 250, top: 145 });
- $("#" + $divID).show();
- $("#" + $divID).stop().animate( $nodePosition );