【问题标题】:pause/resume animation by mouse events jquery通过鼠标事件jquery暂停/恢复动画
【发布时间】:2013-05-12 19:03:22
【问题描述】:

这是一个代码:http://jsfiddle.net/XqS2f/

我知道我需要以某种方式保存块的当前位置或类似的东西......但可能存在另一种更易于使用的解决方案?

$(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);      
});

}

【问题讨论】:

    标签: jquery jquery-animate


    【解决方案1】:

    尝试在准备好的文档中添加此代码和此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);
    });
    

    【讨论】:

    • 感谢您的快速回答,但不会停止......而且工作非常奇怪......当您尝试时有时将光标停留一段时间,当鼠标移开表单块时,这不是恢复。
    猜你喜欢
    • 2011-07-31
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 2011-12-12
    • 2018-04-21
    相关资源
    最近更新 更多