Reputation: 677
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 :
window.scrollTo(0, $("body").offset().top);
window.scrollTo(0, $("#main").offset().top();
The following:
$('html, body').animate({
scrollTop: $('#main').position().top },
1000
);
seems to work in firefox not in chrome
$('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
Upvotes: 2
Views: 251
Reputation: 1302
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/
Upvotes: 0
Reputation: 20626
Try jQuery .scrollTop()
,
$(window).scrollTop(0) //Or $('body').scrollTop(0)
Upvotes: 1