944,199 Members | Top Members by Rank

Ad:
Sep 29th, 2009
-1

cancelling jquery timeouts

Expand Post »
Hi not sure if its technically a timeout but I am building a sliding jquery nav, the sliding is fine.

theres 4 buttons you can click whatever one and they will slide into place even if they are in the middle of sliding, cool. BUT they each also open a loader for 2 seconds then fade in a div.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. $("#nav_1").bind("click",function() {
  2. $("#nav_1").animate({ left: "0px" }, 500, "easeOutCirc");
  3. $("#nav_2").animate({ left: "560px" }, 500, "easeOutCirc");
  4. $("#nav_3").animate({ left: "620px" }, 500, "easeOutCirc");
  5. $("#nav_4").animate({ left: "680px" }, 500, "easeOutCirc");
  6. $('.hidden').css({ display: "none"});
  7. $('#loader').fadeIn().fadeTo(2000, 1).fadeOut(1000, function() {
  8. $(this).fadeOut();
  9. $("#div_1").fadeIn();
  10. });
  11. });
  12. $("#nav_2").bind("click",function() {
  13. $("#nav_1").animate({ left: "0px" }, 500, "easeOutCirc");
  14. $("#nav_2").animate({ left: "60px" }, 500, "easeOutCirc");
  15. $("#nav_3").animate({ left: "620px" }, 500, "easeOutCirc");
  16. $("#nav_4").animate({ left: "680px" }, 500, "easeOutCirc");
  17. $('.hidden').css({ display: "none"});
  18. $('#loader').fadeIn().fadeTo(2000, 1).fadeOut(1000, function() {
  19. $(this).fadeOut();
  20. $("#div_2").fadeIn();
  21. });
  22. });

Problem is when you click through the buttons quickly its keeping track of the buttons clicked/divs to display. So even when you stop clicking it will finish the loader, display the div, finish the next loader, display the next div, etc.

How do i clear that 2 second delay on the loader and just hide it?

Thanks
Similar Threads
Reputation Points: 37
Solved Threads: 1
Posting Whiz in Training
cmills83 is offline Offline
249 posts
since Jun 2004
Sep 30th, 2009
0

Re: cancelling jquery timeouts

You should be able to use jQuery's stop() function which is explained on the jQuery site here.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nauticalmac is offline Offline
5 posts
since Dec 2007
Oct 1st, 2009
0

Re: cancelling jquery timeouts

Didnt seem to work, I need to stop the fades I have going on because they have a delay on them. Any idea how to apply the stop() to a fade, i tried this but it didnt work:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. $(document).ready(function() {
  2. // Reset Nav Icons if logo is clicked
  3. $("#logo").bind("click",function() {
  4. $("#nav_portfolio").animate({ left: "711px" }, 500, "easeOutCirc");
  5. $("#nav_about").animate({ left: "778px" }, 500, "easeOutCirc");
  6. $("#nav_services").animate({ left: "846px" }, 500, "easeOutCirc");
  7. $("#nav_contact").animate({ left: "909px" }, 500, "easeOutCirc");
  8. $("#loader").stop();
  9. $(".content_wrap").fadeOut();
  10. $("#loader").fadeIn().fadeTo(2000, 1).fadeOut(1000, function() {
  11. $(this).fadeOut();
  12. $("#content_home").fadeIn();
  13. });
  14. });
  15. // Navigation sliding effect, page swap functions
  16. $("#nav_portfolio").bind("click",function() {
  17. $("#nav_portfolio").animate({ left: "157px" }, 500, "easeOutCirc");
  18. $("#nav_about").animate({ left: "778px" }, 500, "easeOutCirc");
  19. $("#nav_services").animate({ left: "846px" }, 500, "easeOutCirc");
  20. $("#nav_contact").animate({ left: "909px" }, 500, "easeOutCirc");
  21. $("#loader").stop();
  22. $(".content_wrap").fadeOut();
  23. $("#loader").fadeIn().fadeTo(2000, 1).fadeOut(1000, function() {
  24. $(this).fadeOut();
  25. $("#content_portfolio").fadeIn();
  26. });
  27. });
  28. $("#nav_about").bind("click",function() {
  29. $("#nav_portfolio").animate({ left: "157px" }, 500, "easeOutCirc");
  30. $("#nav_about").animate({ left: "224px" }, 500, "easeOutCirc");
  31. $("#nav_services").animate({ left: "846px" }, 500, "easeOutCirc");
  32. $("#nav_contact").animate({ left: "909px" }, 500, "easeOutCirc");
  33. $("#loader").stop();
  34. $(".content_wrap").fadeOut();
  35. $("#loader").fadeIn().fadeTo(2000, 1).fadeOut(1000, function() {
  36. $(this).fadeOut();
  37. $("#content_about").fadeIn();
  38. });
  39. });
  40. $("#nav_services").bind("click",function() {
  41. $("#nav_portfolio").animate({ left: "157px" }, 500, "easeOutCirc");
  42. $("#nav_about").animate({ left: "224px" }, 500, "easeOutCirc");
  43. $("#nav_services").animate({ left: "292px" }, 500, "easeOutCirc");
  44. $("#nav_contact").animate({ left: "909px" }, 500, "easeOutCirc");
  45. $("#loader").stop();
  46. $(".content_wrap").fadeOut();
  47. $("#loader").fadeIn().fadeTo(2000, 1).fadeOut(1000, function() {
  48. $(this).fadeOut();
  49. $("#content_services").fadeIn();
  50. });
  51. });
  52. $("#nav_contact").bind("click",function() {
  53. $("#nav_portfolio").animate({ left: "157px" }, 500, "easeOutCirc");
  54. $("#nav_about").animate({ left: "224px" }, 500, "easeOutCirc");
  55. $("#nav_services").animate({ left: "292px" }, 500, "easeOutCirc");
  56. $("#nav_contact").animate({ left: "355px" }, 500, "easeOutCirc");
  57. $("#loader").stop();
  58. $(".content_wrap").fadeOut();
  59. $("#loader").fadeIn().fadeTo(2000, 1).fadeOut(1000, function() {
  60. $(this).fadeOut();
  61. $("#content_contact").fadeIn();
  62. });
  63. });
  64. });

thanks for the reply
Reputation Points: 37
Solved Threads: 1
Posting Whiz in Training
cmills83 is offline Offline
249 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Change the name of a file getting downloaded
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Simple form not working through Ajax, works ok from a direct html





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC