Вопрос

I found one really useful jQuery script. With this script I want to scroll div elements on overflow: srcoll to the last element. This works like a charm but doesn't repeat. I've tried many ways to add a looping effect but I'm not that good with JS or jQuery . This is the script:

$(document).ready(function() {
    var wrapper = $('.autoscroll'),
        element = wrapper.find('.ani-item'),
        lastElement = wrapper.find('.img2'),
        lastElementTop = lastElement.position().top,
        elementsHeight = element.outerHeight(),
        scrollAmount = lastElementTop - 2 * elementsHeight;

    $('.autoscroll').animate({
        scrollTop: scrollAmount
    }, 1000, function() {
        lastElement.addClass('current-last');
    }); 
});

If is possible to scroll back to top with a smooth delay effect :} thank you before all!

Sry this is the jsfiddle - http://jsfiddle.net/pixelass/uaewc/5/

Это было полезно?

Решение

http://jsfiddle.net/uaewc/453/

function animateList() {
    $('#listofstuff').animate({
        scrollTop: scrollAmount
    }, 1000, function() {
        lastElement.addClass('current-last');
        setTimeout(function() {
            $('#listofstuff').animate({
                scrollTop: 0
            }, 1000,function() {
                setTimeout(function() {
                    animateList();
                },1000);
            });
        },1000);
    });
}
animateList();

Is that what you wanted?

If you wrap your code in a function you can call it again once the animation has completed.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top