js缓慢滑块
2024-10-08 13:13:46
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
#div1 {width:100px; height:150px; background:red; position:absolute; right:0; bottom:0;}
</style>
<script> window.onscroll=function()
{
var oDiv=document.getElementById('div1'); var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
//alert(document.documentElement.clientHeight);
//oDiv.style.top=document.documentElement.clientHeight-oDiv.offsetHeight+scrollTop+'px';
//alert(document.documentElement.clientHeight);
//document.title=oDiv.offsetHeight;
//alert(oDiv.offsetHeight);
//alert(document.documentElement.scrollTop);
//alert(scrollTop);
//alert(document.documentElement.clientHeight-oDiv.offsetHeight+scrollTop);
startMove(document.documentElement.clientHeight-oDiv.offsetHeight+scrollTop);
} var timer=null;
function startMove(iTarget)
{
var oDiv=document.getElementById('div1'); clearInterval(timer);
timer=setInterval(function() {
var speed=(iTarget-oDiv.offsetTop)/6;
//alert(iTarget-oDiv.offsetTop);
//alert(iTarget);
//alert(speed);
speed=speed>0?Math.ceil(speed):Math.floor(speed); if(oDiv.offsetHeight==iTarget)
{
clearInterval(timer);
}
else
{
oDiv.style.top=oDiv.offsetTop+speed+'px';
}
},30);
} </script>
</head> <body style="height:2000px;">
<div id="div1"></div>
</body>
</html>
最新文章
- 欢迎加入threejs
- UISprite(NGUI)扩展 图片镂空
- Mongodb Manual阅读笔记:CH8 复制集
- Unity 逐步旋转
- 联想 thinkpad fn键关闭,优化使用
- 【mysql】添加对emoji的支持
- CSS重置代码和常用公共代码
- HDOJ_1010 Tempter of the Bone
- 关于linux-Centos 7下mysql 5.7.9的rpm包的安装方式 (转)
- CentOS 6.8编译安装httpd2.2.31+MySQL5.6.31+PHP5.3.27
- 解决WebStorm无法连接到Chrome
- 将Tomcat配置到你的mac电脑上,命令行启动tomcat
- Mysql error 1317导致从库复制断开
- STM32的优先级的理解及其使用
- 下载8000首儿歌的python代码
- 【资源大全】.NET资源大全中文版(Awesome最新版)
- C++ 实现Biginteger
- 算法笔记_184:历届试题 约数倍数选卡片(Java)
- RabbitMQ消息队列生产者和消费者
- Wunderlist 云端任务管理(Todo list)工具