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
  • 117,312
  • 30
  • 193
  • 198

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,150
  • 6
  • 10
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,070
  • 12
  • 50
  • 79
0

try something like this:

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

$( ".yourButtonDownClass" ).on('click', function(){
    window.scroll(0, -300); 
});
metamorph_online
  • 192
  • 1
  • 10
-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');
    });