Jquery sliding gets more delayed for each click
If you login here http://freeri.freehostia.com/utanme/image.php Username/password:Demo123 and press any image and when it slides click the main image, do that a couple of times and suddently you'll notice that the sliding takes longer and longer for each time.
the code im us开发者_C百科ing
$(function(){
$('.slide:last-child img').live('click', function() {
$('.slide:first-child').animate({
marginLeft: '0'
},500);
return false;
});
$('.slide .img').click(function(){
var img = $(this).find('a').attr('href');
var title = $(this).find('h2').text();
var desc = $(this).find('p').text();
$('.slide:last-child img').attr('src',img);
$('.slide:last-child h2').text(title);
$('.slide:last-child #cont').text(desc);
$('body').prepend('<div id="cover"><img src="./images/loader.gif"/></div>');
$('.slide:last-child img').load(function(){
$('#cover').detach();
$('.slide:first-child').animate({
marginLeft: '-900px'
},500);
});
return false;
});
});
what am i missing here? any aid would be greatly appreciated
$('.slide:first-child').stop(true,true).animate({ marginLeft: '-900px' },500});
About stop: http://api.jquery.com/stop/
Additionally I've had issues with live and load events on the same element (not saying it's what is causing your problem here.)
Might be not appropriate, but if you still have issues, try removing the live event before your subsequent load bind. http://api.jquery.com/die/
Edit: Note it's probably bad for performance (to continuously remove and re-add the live binding). I do not mean do this all the time but it may help pinpoint your problem.
Try calling stop(true, true); when the animations allegedly end, there may be some strange calculations going on in the background that mess around with how the callback is set up. I have no idea if this will work, but it is worth a try. :) -Thomas
精彩评论