源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

js滚动条回到顶部的代码

  • 时间:2021-05-17 14:34 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:js滚动条回到顶部的代码
虽然平滑性处理的不好,但非常适合学习
[u]复制代码[/u] 代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> <script type="text/javascript"> //怎么获取网页的高度 让页面一出来就滚动条在最底端 function myScroll() { //前边是获取chrome等一般浏览器 如果获取不到就是ie了 就用ie的办法获取 var x=document.body.scrollTop||document.documentElement.scrollTop; var timer=setInterval(function(){ x=x-100; if(x<100) { x=0; window.scrollTo(x,x); clearInterval(timer); } window.scrollTo(x,x); },"250"); } </script> <title></title> </head> <body id="bd"> <div> <div style="height:1000px;">初始化</div> <div style="height:1000px"> <div style="position:fixed;right:10px;bottom:50px;width:20px;height:70px;background-color:red;cursor:hand;" onclick="myScroll()">返回顶端</div> </div> </body> </html>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部