Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery - back to top

Tags:

jquery

I see this fiddle sample here

I want when "to the top" appear, an click! should scroll to the top smoothly or slow

$(window).scroll(function() {     if ($(this).scrollTop()) {         $('#toTop').fadeIn();     } else {         $('#toTop').fadeOut();     } }); 
like image 461
jhunlio Avatar asked Jan 10 '13 02:01

jhunlio


People also ask

How do I get back to top button in jQuery?

This code must be added just after we included jQuery, in new <script></script> tags: $(function () { $(window). scroll(function() { if ($(this). scrollTop() - 200 > 0) { $('#to-top').

How do you go back to the top in HTML?

Utilize the <a> tag. At the top of your website, put an anchor with specified name. Then your "back to top" link points to it.

How do you get to the top of the page in JavaScript?

Method 1: Using window.scrollTo() The scrollTo() method of the window Interface can be used to scroll to a specified location on the page. It accepts 2 parameters the x and y coordinate of the page to scroll to. Passing both the parameters as 0 will scroll the page to the topmost and leftmost point.


1 Answers

$("#toTop").click(function () {    //1 second of animation time    //html works for FFX but not Chrome    //body works for Chrome but not FFX    //This strange selector seems to work universally    $("html, body").animate({scrollTop: 0}, 1000); }); 

http://jsfiddle.net/fjXSq/161/

like image 167
Explosion Pills Avatar answered Sep 18 '22 14:09

Explosion Pills