javascript 返回顶部按钮
来源:互联网 发布:员工工作日志软件 编辑:程序博客网 时间:2024/04/30 13:13
html代码:
<!DOCTYPE html><html><body><p>JavaScript 能够直接写入 HTML 输出流中:</p><scripttype="text/javascript" src="top.js"></script><p><pre>您只能在 HTML 输出流中使用 <strong>document.write</strong>。如果您在文档已加载后使用它(比如在函数中),会覆盖整个文档。</pre></p><p><pre>您只能在 HTML 输出流中使用 <strong>document.write</strong>。如果您在文档已加载后使用它(比如在函数中),会覆盖整个文档。</pre></p><p><pre>您只能在 HTML 输出流中使用 <strong>document.write</strong>。如果您在文档已加载后使用它(比如在函数中),会覆盖整个文档。</pre></p><p><pre>您只能在 HTML 输出流中使用 <strong>document.write</strong>。如果您在文档已加载后使用它(比如在函数中),会覆盖整个文档。</pre></p><p><pre>您只能在 HTML 输出流中使用 <strong>document.write</strong>。如果您在文档已加载后使用它(比如在函数中),会覆盖整个文档。</pre></p></body></html>
top.js
(function() { var btnId = '__gotop'; var isIE = !!window.ActiveXObject && /msie (\d)/i.test(navigator.userAgent) ? RegExp['$1'] : false; function $() { return document.getElementById(arguments[0]); } function getScrollTop() { return ('pageYOffset' in window) ? window.pageYOffset : document.compatMode === "BackCompat" && document.body.scrollTop || document.documentElement.scrollTop ; } function bindEvent(event, func) { if (window.addEventListener) { window.addEventListener(event, func, false); } else if (window.attachEvent) { window.attachEvent('on' + event, func); } } bindEvent('load', function() { var css = 'background-color:#999;width:50px;height:50px;position:fixed;right:100px;bottom:30px;border-radius:10px;cursor:pointer;display:none;'; if (isIE && isIE < 7) { css += '_position:absolute;_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-30-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)))'; var style = document.createStyleSheet(); style.cssText = '*html{background-image:url(about:blank);background-attachment:fixed;}'; } var html = '<div style="height: 0;width: 0;border:14px solid #999999;border-top: 0 none;border-bottom:14px solid #fff;position: relative;margin:12px 0 0 11px;"><div style="width:8px;height:7px;position:absolute;top:14px;left:-4px;background-color:#fff;overflow: hidden;"></div></div>'; var el = document.createElement('DIV'); el.id = btnId; el.style.cssText = css; el.innerHTML = html; document.body.appendChild(el); el.onclick = function() { (function() { var top = getScrollTop(); if (top > 0) { window.scrollTo(0, top / 1.2) setTimeout(arguments.callee, 10); } })(); }; el.onmouseover = function() { $(btnId).firstChild.style.borderBottom = '14px solid #ddd'; $(btnId).firstChild.firstChild.style.backgroundColor = '#ddd'; }; el.onmouseout = function() { $(btnId).firstChild.style.borderBottom = '14px solid #fff'; $(btnId).firstChild.firstChild.style.backgroundColor = '#fff'; }; } ); bindEvent('scroll', function() { var top = getScrollTop(), display = 'none'; if (top > 0) { display = 'block'; } if ($(btnId)) $(btnId).style.display = display; });})();
0 0
- javascript 返回顶部按钮
- 返回顶部按钮
- 返回到顶部按钮
- 返回顶部按钮
- 返回顶部按钮实现
- 返回顶部按钮
- jquery返回顶部按钮
- 返回顶部按钮
- 返回顶部按钮
- 右下角返回顶部按钮
- 返回顶部小按钮
- JavaScript中返回顶部按钮(匀速、减速)写法
- javascript 返回顶部
- javascript返回顶部
- javascript返回顶部效果
- javascript返回页面顶部
- 返回顶部JavaScript插件
- javascript 慢慢返回顶部
- HOJ 2014 winter 转16进制
- zoj 1088 System Overload
- LeetCode的LastWord
- H264(NAL简介与I帧判断)
- php表单验证,防垃圾机器人刷表单
- javascript 返回顶部按钮
- 冬天
- linux文件系统初始化过程(3)---加载initrd(上)
- DebugView使用详解
- 黑马程序员高级视频学习笔记 将一个系统盘中的文件复制到另一个系统盘中
- 多个信号对应单个槽的实现
- Linux内核 2.4和2.6的进程内核
- TabBarController
- ICT实习第一周