代码1:
$('body,html').animate({
scrollTop: 0
}, 1000);
return false;
});
代码2:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body style="height:6000px;position: relative;">
<a href="javascript:;" style="position: absolute;right:0;bottom:0;" id="btn">返回顶部</a>
<script type="text/javascript">
window.onload=function()
{
var btn=document.getElementById("btn");
var scrolldelay;
var iNow=0;
var top=document.body.scrollTop | document.documentElement.scrollTop;
window.onscroll=function()
{
top = document.body.scrollTop | document.documentElement.scrollTop;
if(top<=0)
{
clearInterval(scrolldelay);
}
};
btn.onclick=function()
{
scrolldelay = setInterval(pageScroll,60);
function pageScroll() {
iNow+=200;
window.scrollBy(0,-iNow);
}
};
}
</script>
</body>
</html>