cancelling jquery timeouts

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jun 2004
Posts: 247
Reputation: cmills83 is an unknown quantity at this point 
Solved Threads: 1
cmills83 cmills83 is offline Offline
Posting Whiz in Training

cancelling jquery timeouts

 
-1
  #1
Sep 29th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 5
Reputation: nauticalmac is an unknown quantity at this point 
Solved Threads: 0
nauticalmac nauticalmac is offline Offline
Newbie Poster

Re: cancelling jquery timeouts

 
0
  #2
Sep 30th, 2009
You should be able to use jQuery's stop() function which is explained on the jQuery site here.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 247
Reputation: cmills83 is an unknown quantity at this point 
Solved Threads: 1
cmills83 cmills83 is offline Offline
Posting Whiz in Training

Re: cancelling jquery timeouts

 
0
  #3
Oct 1st, 2009
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
Reply With Quote Quick reply to this message  
Reply

Tags
jquery

Message:




Views: 680 | Replies: 2
Thread Tools Search this Thread



Tag cloud for jquery
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC