2

I'm using a ui theme called nightsky

After I scroll to the bottom of the page I want to go back to the top of the page.

What I have tried already in dev console :

  1. window.scrollTo(0, $("body").offset().top);
  2. window.scrollTo(0, $("#main").offset().top();
  3. The following:

    $('html, body').animate({
        scrollTop: $('#main').position().top },
        1000
    );
    

    seems to work in firefox not in chrome

  4. $('html,body').animate({scrollTop: 0});

I am looking for a code that can be executed in console! no on-click listeners etc...just few lines of code

Tabraiz Ali
  • 677
  • 9
  • 36

4 Answers4

1

Try jQuery .scrollTop(),

$(window).scrollTop(0)   //Or $('body').scrollTop(0)

Demo

Shaunak D
  • 20,588
  • 10
  • 46
  • 79
0

why dont you use <a href="#header">Go to top</a>

Rahiil
  • 110
  • 1
  • 11
  • first of all its a button i have to do some process on click of the button if there is an error go to the top of the page! – Tabraiz Ali Jul 09 '14 at 08:09
0

Try this

$(document).ready(function(){
  $('.top').on('click', function() {
     $('html,body').animate({'scrollTop':'0px'},1000);
  });
});

here is demo link : http://jsfiddle.net/jkkheni/JWJ5N/13/

jignesh kheni
  • 1,282
  • 1
  • 9
  • 22
0

You can try:

<a href="#top">Click</a>