Lorem Ipsum //

Back to Top

$(document).ready(function() { $("a.topLink").c">
 | 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
lpki123
11年前发布

jQuery实现快速平滑回到顶部

这个功能很常见,在网站底部添加一个让访客快速回到页面顶部的功能,下面是实现这个功能的示例代码:

// HTML:  // <h1 id="anchor">Lorem Ipsum</h1>  // <p><a href="#anchor" class="topLink">Back to Top</a></p>     $(document).ready(function() {      $("a.topLink").click(function() {          $("html, body").animate({              scrollTop: $($(this).attr("href")).offset().top + "px"          }, {              duration: 500,              easing: "swing"          });          return false;      });  });