实现返回顶部按钮一直在页面底部(兼容ie6)
2016-05-26 15:40
656 查看
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script type="text/javascript" src="./jquery-1.8.0.js"></script> <style type="text/css"> .back_top {width: 100px; height: 100px; border: 1px solid purple; text-align: center; line-height: 100px; display: none;} .change {position: absolute; left: 600px; display: block; cursor: pointer;} </style> </head> <body> <div style="width:500px; height:2200px; border:1px solid red; margin:0 auto; position:relative;"> <div style="margin-top:10px; border:1px solid blue;">a</div> <div style="margin-top:2140px; border:1px solid blue;">b</div> <div class="back_top"> 返回顶部 </div> </div> <script type="text/javascript"> $(window).resize(function() { $('.back_top').css('bottom', $(document.body).height() - $(window).scrollTop() - $(window).height() + 10); }); $(window).scroll(function() { $('.back_top').addClass('change'); $('.back_top').css('bottom', $(document.body).height() - $(window).scrollTop() - $(window).height() + 10); if($(window).scrollTop() === 0) { $('.back_top').removeClass('change'); } }); $('.back_top').on('click', function() { $(window).scrollTop(0); }); </script> </body> </html>
相关文章推荐
- 密码框提示文字
- 自写jQuery插件,实现简单网页遮罩层/弹出层功能,兼容IE6、IE7
- 兼容到IE6的进度条
- 好消息! 不用再羡慕Python有jupyter 我R也有Notebook了【附演示视频】
- 利用poi导出excel
- Linux 代码格式化工具 indent
- 内存访问
- IntelliSense: "const char *" 类型的实参与 "LPCTSTR" 类型的形参不兼容
- JSPatch
- 自定义的TextView跑马灯
- Codeforces Round #354 (Div. 2) C. Vasya and String 二分
- 12.static 详解
- 设计模式:抽象工厂模式
- js读取mongodb日期加8个月,再更新数据
- 多线程学习(一)线程概念&线程的创建
- Android中Dialog从底部划入
- 理解使用递归及堆栈的算法处理八皇后问题
- Android Studio(AS)-->导入项目
- 二叉树转双向列表-仿写。
- sqlserver 中临时表、临时变量和with as关键词创建“临时表”的区别