<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<style>
body{
height: 2000px;
}
div{
width: 200px;
height: 200px;
background-color: #ff0000;
position: absolute;
right: 0;
bottom: 0;
}
</style>
</head>
<body>
<div id="test"></div>
<script>
(function(w,d){
var div= d.getElementById('test'),
de=document.documentElement,
t=null,
scrollTop= 0,
windowHeight=parseInt(window.innerHeight||de&&de.clientHeight||document.body.clientHeight);
window.onscroll=function(){
if(t){
window.clearTimeout(t);
}
t=window.setTimeout(function(){
scrollTop=parseInt(de&&de.scrollTop||document.body.scrollTop);
div.style.top=windowHeight+scrollTop-200+'px';
},20);
}
})(window,document)
</script>
</body>
</html>
类似这样试试
<html>
<head>
<title></title>
<meta charset="utf-8" />
<style>
body{
height: 2000px;
}
div{
width: 200px;
height: 200px;
background-color: #ff0000;
position: absolute;
right: 0;
bottom: 0;
}
</style>
</head>
<body>
<div id="test"></div>
<script>
(function(w,d){
var div= d.getElementById('test'),
de=document.documentElement,
t=null,
scrollTop= 0,
windowHeight=parseInt(window.innerHeight||de&&de.clientHeight||document.body.clientHeight);
window.onscroll=function(){
if(t){
window.clearTimeout(t);
}
t=window.setTimeout(function(){
scrollTop=parseInt(de&&de.scrollTop||document.body.scrollTop);
div.style.top=windowHeight+scrollTop-200+'px';
},20);
}
})(window,document)
</script>
</body>
</html>
类似这样试试
解决方案 »
- 如何读取xml的值
- 关于根据form中option的值执行不同事件
- 求一款兼容IE6的上下翻滚JS代码
- 如果得到下拉选择框中的那个"value"
- 知道了字符,如何转而设置 event.keyCode?
- 如何让网页在别人不知道的情况下自动加入收藏夹? 谢谢了
- 怎样做到点击按钮,使按钮所在的页面有以下的属性?
- 菜鸟求救:请大家帮忙,如何得到Cookies,急
- 那种方式可以递交大量的数据,而递交后又可以方便的把它们存入数据库中?
- 大神指导,flexgrid如何加载获取的json数据,因为要动态生成列,所以只能先获取ajax数据
- 求大 神指导
- 关于新生成元素怎么绑定js事件,事件是bootstracp里的
现在基本都支持了 除了ie6
<html>
<head>
<title></title>
<meta charset="utf-8" />
<style>
#test{
width: 200px;
height: 200px;
background-color: #ff0000;
position: fixed;
right: 0;
bottom: 0;
}
div{
width: 200px;
height: 2000px;
background-color: yellow;
}
</style>
</head>
<body>
<div id="test"></div>
<div></div>
<script>
(function(w,d){
var div= d.getElementById('test');
if(div.currentStyle&&div.currentStyle.position.toLowerCase()!='fixed'){
div.style.position='absolute';
change();
}
function change(){
var de=document.documentElement,
t=null,
scrollTop= 0,
windowHeight=parseInt(window.innerHeight||de&&de.clientHeight||document.body.clientHeight);
window.onscroll=function(){
if(t){
window.clearTimeout(t);
}
t=window.setTimeout(function(){
scrollTop=parseInt(de&&de.scrollTop||document.body.scrollTop);
div.style.top=windowHeight+scrollTop-200+'px';
},20);
}
}
})(window,document)
</script>
</body>
</html>
大体这样