JavaScript 运动之页面悬浮框
来源:互联网 发布:js脚本被劫持 广告 编辑:程序博客网 时间:2024/05/16 05:58
document.documentElement.scrollTop获取当前页面的滚动条纵坐标
document.body.scrollTop恒为0需要用document.documentElement.scrollTop
代替,IE5.5之后已经不支持document.body.scrollX对象
document.body.clientHeight ==> BODY对象高度
document.documentElement.clientHeight ==> 可见区域高度
HTML代码
<!DOCTYPE html>
<html>
<head>
<title>domScroll.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
#div1{width:60px;height:100px;background-color:#EEE;position: absolute;right: 0;bottom:0;border:1px solid red;border-radius:5px;line-height:100px;font-size:18px;text-align:center;}
</style>
<script type="text/javascript" src="../js/domScroll.js"></script>
</head>
<body style="height:2000px;">
<div id="div1">Scroll</div>
</body>
</html>
js代码
window.onscroll = function(){
var odiv = document.getElementById('div1');
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
//startMove(document.documentElement.clientHeight - odiv.offsetHeight+scrollTop);页面右下角悬浮
startMove(parseInt((document.documentElement.clientHeight - odiv.offsetHeight)/2)+scrollTop);//页面中间悬浮
}
var timer = null;
function startMove(iTarget){
var odiv = document.getElementById('div1');
clearInterval(timer);
timer = setInterval(function(){
var speed = (iTarget - odiv.offsetTop)/4;
speed = speed>0?Math.ceil(speed):Math.floor(speed);
if(odiv.offsetTop == iTarget){
clearInterval(timer);
}else{
odiv.style.top = odiv.offsetTop+speed+"px";
}
},30);
}
- JavaScript 运动之页面悬浮框
- (40)JS运动之右下角悬浮框
- (41)JS运动之右侧中间悬浮框(对联悬浮框)
- JavaScript运动之缓冲运动
- JavaScript 运动之匀速运动
- JavaScript之链式运动
- js运动技术--右侧悬浮框!
- 页面悬浮框
- [Javascript]右侧悬浮框
- [Javascript]右侧悬浮框
- JavaScript 运动之淡入淡出
- JavaScript 动画之缓冲运动
- JavaScript 动画之链式运动
- JavaScript 动画之弹性运动
- JavaScript 动画之碰撞运动
- JavaScript运动框架(二):解决防抖动问题、悬浮对联
- javascript滚动条事件动态悬浮页面对象
- JavaScript 运动之侧边分享栏
- Hadoop入门+HDFS命令
- 记录可控硅控制电路不能完全关闭的问题解决
- Spark 下使用分析函数报错
- 默认打开USB调试功能
- NullPointerException 的几种类型
- JavaScript 运动之页面悬浮框
- SimpleDateFormat 转化为12小时制或者是24小时制
- WinForm控件设计:DataGridView的行统计实现
- 第十一周 项目4-类族的设计(2)
- c++函数符重载
- 第十二周 项目3-日期时间类
- Windows7硬盘按照CentOS6.4
- linux系统DDR中ramdisk,创建
- RSA 算法介绍