爱玺玺

爱玺玺的生活日记本。wx:lb87626

js变速回到页面顶部

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

<title>Document</title>

<script type="text/javascript">

window.onload=function(){

var btn=document.getElementById("returntop");

var timer=null;

btn.onclick=function(){

timer=setInterval(function(){

if (scroll_top==0) { clearInterval(timer)}

var scroll_top=document.documentElement.scrollTop||document.body.scrollTop;

//变速回到顶部

var speed=scroll_top/8;

document.documentElement.scrollTop=document.body.scrollTop=(scroll_top-speed);

console.log(scroll_top+" "+speed);

},20);

}


}


</script>


</head>

<bodyx>

<div style="height: 4000px;"></div>

<input type="button" value="回到顶部" id="returntop">

</body>

</html>


发表评论:

Powered By Z-BlogPHP 1.4 Deeplue Build 150101

Copyright Your WebSite.Some Rights Reserved.

蜀ICP备11021721号-5