November 14, 200917 yr Hi, Im building a new portfolio site at http://www.velawebdev.com I've noticed that if you click on the links too quickly the other pages begin to load prematurely. Any ideas on how I can fix the jquery for this? Here's a look at the source jQuery script: http://pastebin.com/d16e624d6 Thanks! G
November 14, 200917 yr It's the intervals queueing up. You need to assign all the intervals to the same var, so var timeout = setTimeOut(...); If that doesn't work try a callback function on the jqeury animate which basically sets a alreadyrunning variable to true and when it ends to false. Also append queue:false into the jquery options (for animate)
November 14, 200917 yr Author Hey Thanks for the input. So, the functions in each of the timeouts each "show()" a different element so how can I use one var for all? Also, I'm not 100% certain about what you meant about "ry a callback function on the jqeury animate". Could you please elaborate a bit? (jQuery Newbie here!) Thanks! G
November 14, 200917 yr jQuery('selector').animate({params}, speed, callback); for your callback you can put either a function name, or something like function() { alert("reached my callback"); } Hope this helps!
November 14, 200917 yr Hey Thanks for the input. So, the functions in each of the timeouts each "show()" a different element so how can I use one var for all? Also, I'm not 100% certain about what you meant about "ry a callback function on the jqeury animate". Could you please elaborate a bit? (jQuery Newbie here!) Thanks! G As ChristopherDarling says just link it to an external function rather than using a callback function. E.g. var intervalRunning = false; function intervalStart(obj) { intervalRunning = true; } function intervalEnd(ob) { intervalRunning = false; } You would then do a check before using jquery animate. e.g. if(userClicksThis && !intervalRunning) { // run here (jquery animate } So heres something i haven't tested... $(function(){ $('.hidden').css({'position': 'relative', 'right': '-650px'}); $('.disp-none').css('display', 'none'); var $xhtml_a = $('#xhtml-a'); var $desc = $('#descriptions'); var $visibleChildren = $('#descriptions').children(); var $xhtml_p = $('#xhtml'); var $css_p = $('#css'); var $jquery_p = $('#jquery'); var $drupal_p = $('#drupal'); var anchors = $('#languages a'); var intervalRunning = false; $('.toggle-definition').click(function(){ var this_id = $(this).attr('id'); anchors.removeClass('active'); $(this).addClass('active') $visibleChildren.fadeOut(500, function(){$(this).css('right', '-650px') }); if(this_id == 'xhtml-a' && !intervalRunning){ intervalStart(); setTimeout(function(){$xhtml_p.show().animate({'right': '0'}, 1000); }, 600,intervalEnd()); } else if (this_id == 'css-a' && !intervalRunning){ intervalStart(); setTimeout(function(){$css_p.show().animate({'right': '0'}, 1000); }, 600,intervalEnd()); } else if (this_id == 'jquery-a' && !intervalRunning){ intervalStart(); setTimeout(function(){$jquery_p.show().animate({'right': '0'}, 1000); }, 600,intervalEnd()); } else if (this_id == 'drupal-a' && !intervalRunning){ intervalStart(); setTimeout(function(){$drupal_p.show().animate({'right': '0'}, 1000); }, 600,"",intervalEnd()); } return false; }); function intervalStart() { intervalRunning = true; } function intervalEnd() { intervalRunning = false; }
Create an account or sign in to comment