<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn">
<HEAD>
<TITLE>添加浮动按钮点击滚动到网页底部的纯JavaScript演示代码(goBottom)by PurpleEndurer</TITLE>
<style type="text/css">
#goBottomBtn {float:right; POSITION: fixed; TEXT-ALIGN: center; LINE-HEIGHT: 20px; WIDTH: 30px; BOTTOM: 65px; FONT-SIZE: 12px; CURSOR: pointer; RIGHT: 0px; _position: absolute; _right: auto; border: 1px solid gray; background:green; color:white;}
</style>
</HEAD>
<BODY>
<p>添加浮动按钮点击滚动到网页底部的纯JavaScript演示代码(goBottom) by PurpleEndurer <a href="http://blog.csdn.net/purpleendurer">http://blog.csdn.net/purpleendurer</a></p>
<p>IE9、11,Maxthon 1.6.7,Firefox30、31,360极速浏览器7.5.3.308下测试正常</p>
<p><a href="#1" onclick="window.scrollTo(0,99999);return false;">跳到网页底部方法1</a> <a href="#1" onclick="window.scrollTo(0,99999);return false;">跳到网页底部方法2</a></p>
<script type="text/javascript">
<!--
//添加99行文字
function writeLine()
{
for (var j=0; j < 100; j++)
{
document.writeln('<p>'+ j +' 添加浮动按钮点击滚动到网页底部的纯JavaScript演示代码<p>');
}
}
writeLine();
function goBottomEx()
{
function addGoBottomDiv()
{
var div = document.createElement('div');
div.innerHTML = '<br /><span style="font-size:30px;" title="直达底部">↓</span>';
div.setAttribute('id', 'goBottomBtn');
document.body.appendChild(div);
}
var o = document.getElementById('goBottomBtn');
if (null==o)
{
addGoBottomDiv();
showBottomBtn();
}
o = document.getElementById("goBottomBtn");
function getScrollTop()
{
return document.documentElement.scrollTop || document.body.scrollTop;
}
function setScrollBottom(value) {
document.body.scrollTop += value;
if (0==document.body.scrollTop){
document.documentElement.scrollTop += value;
}
}
function isBottom() {
var a = document.documentElement.clientHeight || document.body.clientHeight;
var b = document.documentElement.scrollTop || document.body.scrollTop;
var c = document.documentElement.scrollHeight || document.body.scrollHeight;
return (a+b >= c);
}
function showBottomBtn(){
var o = document.getElementById('goBottomBtn');
o.style.display = isBottom() ? "none" : "";
}
window.onscroll = function() {
showBottomBtn();
}
o.onmousemove = function() {
this.style.background = "#33cc66";
}
o.onmouseout = function() {
this.style.background = "green";
}
o.onclick = function() {
var goBottom = setInterval(scrollMove, 10);
function scrollMove() {
setScrollBottom((getScrollTop() + 100) / 5); //网页刚载入完成时getScrollTop()返回值为0
if (isBottom()) {clearInterval(goBottom);}
}//scrollMove()
}//o.onclick
}//goBottomEx()
goBottomEx()
//-->
</script>
</BODY>
</HTML>

紫郢剑侠
- 粉丝: 2613
最新资源
- 基于Android平台的股票查询系统的设计与开发毕业设计论文.doc
- 各年度按季度数据分析表excel模板.xlsx
- 基于无线传感器网络的智能智能作战服毕业论文.doc
- C语言实践的心得体会.doc
- 投放网站广告协议书.docx
- 教育行业信息化研究报告.pptx
- 项目管理教材--如何把事情做漂亮.ppt
- 种改进的MRP批量决策的优化模型与算法研究分析.doc
- Module4PlanesshipsandtrainsUnit1Helivesthefarthest.pptx
- 第1课时StartingoutUnderstandingideas.pptx
- 工业品营销策略与项目管理.doc
- 境外项目管理工作经验与教训小结论文.doc
- 电力系统及其自动化课件:电缆基础知识与工程应用.ppt
- 毕业设计-论文单片机实时数据采集显示系统设计论文.doc
- 基于网络的证券与期货专业开放式综合实训平台建设研究分析论文.doc
- 班级网站建设方案.dox.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


