没有合适的资源?快使用搜索试试~ 我知道了~
运行原理 通过定时器30毫秒执行一次滚动条上升,每次上升的高度为当前高度的80%,这样就达到了上升缓冲的动画效果。 判断当滚动条高度超过一屏时,按钮显示,默认隐藏 知识要点 scrollTop//获取滚动条高度 需要写兼容 clientHeight//可视窗口高度 需要写兼容 setInterval//定时器 [removed]//滚动触发事件 完整代码 <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <t
资源推荐
资源详情
资源评论
原生原生js实现返回顶部缓冲效果实现返回顶部缓冲效果
运行原理运行原理
通过定时器30毫秒执行一次滚动条上升,每次上升的高度为当前高度的80%,这样就达到了上升缓冲的动画效果。
判断当滚动条高度超过一屏时,按钮显示,默认隐藏
知识要点知识要点
scrollTop//获取滚动条高度 需要写兼容
clientHeight//可视窗口高度 需要写兼容
setInterval//定时器
window.onscroll//滚动触发事件
完整代码完整代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>demo</title>
<style>
body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{margin:0;padding:0;}
h1,h2,h3,h4,h5,h6{font-size:100%;}
address,cite,dfn,em,var{font-style:normal;}
code,kbd,pre,samp{font-family:courier new,courier,monospace;}
ul,ol{list-style:none;}
a{text-decoration:none;}
a:hover{text-decoration:none;}
sup{vertical-align:text-top;}
sub{vertical-align:text-bottom;}
legend{color:#000;}
fieldset,img{border:0;}
button,input,select,textarea{font-size:100%;}
table{border-collapse:collapse;border-spacing:0;}
.clear{clear: both;float: none;height: 0;overflow: hidden;}
.bg{background:#9B1BC5; width: 1000px; height: 3000px; margin: 0 auto;}
#gotop{width: 50px; height: 50px; background:#5490F5; color: #fff; position: fixed; left: 50%; bottom: 30px; text-align: center; font-family: "Microsoft
Yahei",tahoma,arial; font-size: 14px; cursor: pointer; margin-left: 520px; display: none;}
#gotop span{display: block;padding: 5px;}
</style>
</head>
<body>
<div class="bg"></div>
<div id="gotop"><span>返回顶部</span></div>
<script type="text/javascript">
//在页面加载完后立即执行多个函数方案
function addloadEvent(func){
var oldonload=window.onload;
if(typeof window.onload !="function"){
window.onload=func;
}
else{
window.onload=function(){
if(oldonload){
oldonload();
}
func();
}
}
}
//在页面加载完后立即执行多个函数方案结束
addloadEvent(b);
function b(){
var gotop=document.getElementById("gotop");
var timer;
var tf=true;
//滚动触发
window.onscroll=function(){
//获取滚动条高度
var ostop=document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
//获取窗口可视区域高度
//console.log(ostop)
var ch=document.documentElement.clientHeight||document.body.clientHeight;
//如果页面超过一屏高度按钮显示,否则隐藏
if(ostop>=ch){
资源评论
weixin_38644599
- 粉丝: 11
- 资源: 904
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 一种改进的Goldstei...-InSAR干涉图滤波算法-于晓歆.pdf
- 陈慧琳 - 今生你作伴 [mqms2].mp3
- The Experiment 2 of Engineering Electromagnetics.pdf
- Engineering-Electromagnetic-Theory-Lab-4.pdf
- Engineering electromagnetic theory-1.docx
- The Experiment 4 of Engineering Electromagnetics.pdf
- Engineering-Electromagnetic-Theory-Lab-3.pdf
- The Experiment 3 of Engineering Electromagnetics.pdf
- Engineering electromagnetic theory-2.docx
- tensorflow-gpu-2.7.0-cp37-cp37m-manylinux2010-x86-64.whl
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功