Frage

okay I know how to smooth scroll to an anchor but how do I smooth scroll a certain static amount (ie. 300px) every time I click a certain object until I reach the end of my page. I can do this once but how bout doing it over and over?

War es hilfreich?

Lösung

var pixelsToMove = 50;

$('.myButton').click(function () {
    var currentScrollTopValue = $('#container').scrollTop();

    $('#container').scrollTop(currentScrollTopValue + pixelsToMove);

});

https://api.jquery.com/scrollTop/

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top