0

I have this JavaScript that let me scroll the page up / down by clicking on the top / bottom of the page.

$(function() {
$("#next").on("click", function() {
    $("body").animate({"scrollTop": window.scrollY + (window.innerHeight - 60)}, 100);
    return false;
});
}); 

$(function() {
$("#previous").on("click", function() {
    $("body").animate({"scrollTop": window.scrollY - (window.innerHeight - 60)}, 100);
    return false;
});
});

Have a look at the JSFIDDLE here: https://jsfiddle.net/cztqjwb2/3/

Any idea how to make it cross-browser?

1 Answer 1

3

Some browsers attach the scrollbar to the body, other to the html element.

You'd make it cross browser like this

$("html, body").animate( ....

To make it work in older IE as well, you have to replace scrollY with something, jQuery seems like the obvious choice

$("html, body").animate({
    scrollTop: $(window).scrollTop() + $(window).height() - 60
}, 100);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.