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?
            Asked
            
        
        
            Active
            
        
            Viewed 60 times
        
    0
            
            
        - 
                    http://stackoverflow.com/questions/6677035/jquery-scroll-to-element – Pete Jan 04 '16 at 12:35
4 Answers
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');
    });
 
    
    
        Oleg Bereziuk
        
- 9
- 4

