0

I have two buttons with position:fixed on my website. What i need is to while clicking on a top button the window scrolls top on 300px, the same with bottom, it scrolls bottom on 300px. Any ideas how to make this?

enter image description here

James Donnelly
  • 126,410
  • 34
  • 208
  • 218

4 Answers4

1

scroll down:

$("#buttonUp").click(function() {
    $('html,body').animate({
        scrollTop: window.scrollY + 300},
        'slow');
});

scroll up:

$("#buttonDown").click(function() {
    $('html,body').animate({
        scrollTop: window.scrollY - 300},
        'slow');
});
Jurij Jazdanov
  • 1,248
  • 8
  • 11
0

Use:

window.scrollBy(x, y)

e.g.

window.scrollBy(0, 300);

or

window.scrollBy(0, -300)

If you are using jQuery, you may use:

$(window).scrollTop(value)
Ashraf Bashir
  • 9,686
  • 15
  • 57
  • 82
0

try something like this:

$( ".yourButtonUpClass" ).on('click', function(){
    window.scroll(0, 300); 
});

$( ".yourButtonDownClass" ).on('click', function(){
    window.scroll(0, -300); 
});
metamorph_online
  • 204
  • 2
  • 11
-1

First variant works for me! Thanks!

$("#scrollBot").click(function() {
        $('html,body').animate({
            scrollTop: window.scrollY + 300},
            'slow');
    });

    $("#scrollTop").click(function() {
        $('html,body').animate({
            scrollTop: window.scrollY - 300},
            'slow');
    });