0

I have a problem with jQuery vertical scroll.

I have to add some animation on this example :

$(document).ready(function() {
    var timeoutId = 0;

    function scrollIt(amount) {
        $('#scroller').scrollTop($('#scroller').scrollTop()+amount);
    }

    $('#down').mousedown(function () {
        timeoutId = setTimeout(scrollIt(5), 1000);
    }).bind('mouseleave', function () {
        clearTimeout(timeoutId);
    });

    $('#up').mousedown(function () {
        timeoutId = setTimeout(scrollIt(-5), 1000);
    }).bind('mouseleave', function() {
        clearTimeout(timeoutId);
    });
});

Here is a fiddle : http://jsfiddle.net/TPKDG/1/

and I don't know how :(

where I have to add .animation()?

Thank's a lot for help

Pranav 웃
  • 8,469
  • 6
  • 38
  • 48
  • this question was already addressed here: http://stackoverflow.com/questions/4034659/is-it-possible-to-animate-scrolltop-with-jquery – WebChemist Dec 09 '12 at 10:08

1 Answers1

0

Please see if this update helps you : http://jsfiddle.net/TPKDG/27/

$(document).ready(function() {
var timeoutId = 0;

function scrollIt(amount) {
    $('#scroller').animate({
        scrollTop: $('#scroller').scrollTop() + amount
    });
}

$('#down').mousedown(function() {
    timeoutId = setTimeout(scrollIt(5), 1000);
}).bind('mouseleave', function() {
    clearTimeout(timeoutId);
});

$('#up').mousedown(function() {
    timeoutId = setTimeout(scrollIt(-5), 1000);
}).bind('mouseleave', function() {
    clearTimeout(timeoutId);
});
});​
Anujith
  • 9,370
  • 6
  • 33
  • 48