如果您在这里登录 http://freeri.freehostia.com/utanme/image.php 用户名/密码:Demo123 并按任何图像,当它滑动时单击主图像,这样做几次 突然之间你会注意到每次滑动的时间越来越长。
使用
的代码$(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;
});
});
我在这里失踪了什么? 任何援助将不胜感激
答案 0 :(得分:2)
尝试调用stop(true,true);当动画据称结束时,可能会在后台进行一些奇怪的计算,这些计算会混乱回调的设置方式。我不知道这是否有效,但值得一试。 :) -Thomas
答案 1 :(得分:2)
$('.slide:first-child').stop(true,true).animate({ marginLeft: '-900px' },500});
关于停止: http://api.jquery.com/stop/
此外,我在同一元素上遇到了有关实时和加载事件的问题(不是说这是导致问题的原因。)
可能不合适,但如果仍有问题,请尝试在后续加载绑定之前删除实时事件。 http://api.jquery.com/die/
编辑:注意它可能对性能有害(连续删除并重新添加实时绑定)。我不是故意这样做,但它可能有助于查明你的问题。