jQuery 返回顶部按钮代码

阅读 (1088)
h5 常用功能:点击按钮返回顶部

html:

创建一个按钮,对应写好你自己样式,宽高之类的

<a href="javascript:;" class="top">↑</a>

js:

用jQuery animate实现滚动到指定高度

$('.top').click(function() {
    $("html, body").animate({
         scrollTop: 0
    }, 800); // 总耗间800ms
    return false;
});

 

更新于:2018-06-19 16:53:22
返回顶部