1

I couldn't find another thread on this. I have a button that should scroll back up to the top of the page and the same code works on another site. On this site, however, I can't seem to get it to scroll - it just jumps to the top of the page.

Code is:

$(function() {
    $(".btn-default").on('click', function() {
        $("HTML, BODY").animate({
            scrollTop: 0
        }, 1000);
    });
});
vinayakj
  • 5,591
  • 3
  • 28
  • 48
  • the code is correct, check If your button is a anchor tag and has href="#somethingOrJust#", because that may be causing problem, can you let us know the button html – vinayakj May 02 '15 at 17:16
  • Check this : http://stackoverflow.com/questions/8917921/cross-browser-javascript-not-jquery-scroll-to-top-animation Second Link :http://stackoverflow.com/questions/1144805/how-do-i-scroll-to-the-top-of-the-page-with-jquery – Raj May 02 '15 at 17:24

2 Answers2

1

$('html, body').animate({ scrollTop: $("#target-element").offset().top }, 1000);

This will scroll the page down to #target-element over a period of one second (1,000 milliseconds = 1 second).

Raj
  • 199
  • 1
  • 1
  • 14
0

There is no problem in your code it's perfect.Here you use jquery animate function, Please make sure you add JQuery perfectly. Your can also check you browser console

Payer Ahammed
  • 887
  • 1
  • 5
  • 16