2013-05-12 90 views
0

这里简历动画代码:http://jsfiddle.net/XqS2f/暂停/鼠标事件的jQuery

我明白我需要保存块或类似这样的东西不知何故当前位置......但可能存在另一种解决方案是更容易使用?

$(function() { 
var startTime = new Date();  
tl = $('#thumbs_list'); 
tl.css('overflow', 'hidden'); 

var slider = $('#thumbs_list_frame'), 
    items = slider.find('li'); 
var sliderHeight = slider.height(), 
    itemsNum = items.length, 
    itemHeight = items.height(); 


slider.css('top', '-' + (sliderHeight + itemHeight) + 'px'); 

var startPos = slider.css('top'); 

items.first().before(items.clone()); 
items.last().after(items.clone()); 

scrollItems(slider,sliderHeight,itemHeight,startPos,4); 
var endTime = +new Date(); 
var diff = endTime - startTime; 

setInterval(function(){ 
    scrollItems(slider,sliderHeight,itemHeight,startPos,4); 
}, 300); 

});

function scrollItems(container,targetsHeight,increment,startPos,temps)var secs = temps * 3000;

container.mouseover(function(){ 
    container.stop(true); 
}).mouseout(function(){ 
    //container.animate(); 
}); 

container.animate({ 
    'top': '-' + ((targetsHeight * 2) + increment) + 'px' 
}, secs, 'linear', function() { 
    container.css('top', startPos);  
}); 

}

回答

0

尝试在文件准备添加此代码,这jsfiddle

var itvl = setInterval(function(){ 
     scrollItems(slider,sliderHeight,itemHeight,startPos,4); 
    }, 4000); 

    $('#container').hover(function(){ 
     clearInterval(itvl); 
     $('#slider').stop(); 
    },function() { 
     var itvl = setInterval(function(){ 
      scrollItems(slider,sliderHeight,itemHeight,startPos,4); 
     }, 4000); 
}); 
+0

感谢您快速的解答,但不会停止......并且工作很奇怪......当你尝试有时候保持光标一段时间,这是不会恢复时,做鼠标离开形式块。 – qant 2013-05-12 11:52:00