请问如何判断div被滚动到浏览器顶部? 我想弄个div,它离顶部有段距离,当它被滚动到浏览器顶部的时候,它就固定不动。请问该如何判断? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if(document.getElementById("test")>=document.getElementById("test").offsetTop)不知道行不行~~ if(document.body.scrollTop>=document.getElementById("test").offsetTop) <html><head> <title></title></head><body> <div style="height:960px;background:#330000;">teatteat</div> <div id="t" style="height:24px;background:#000000;color:#ffffff;text-align:center;">teatteat</div> <div style="height:960px;background:#333333;">teatteat</div><script type="text/javascript">document.body.onscroll=function(){ if(document.body.scrollTop>=document.getElementById("t").offsetTop){ document.getElementById("t").style.position="absolute"; document.getElementById("t").style.top=document.body.scrollTop; } else { document.getElementById("t").style.position="static"; document.getElementById("t").style.top=document.body.scrollTop; }} </script></body></html>随便写的,兼容可能有问题~~而且不流畅 求助关于JS代码问题 jquery easyui tree 加载不出来 求解 两段JS代码冲突了 高手们帮忙看看怎么改呀 关于自动提示 mouseover和mouseout事件的问题 为什么javascript取不到图象的宽和高 extjs的multiselect怎么setvalue啊? 代码兼容问题 字符型转换成数字不成功!请教!!!急 怎样在textarea中现实图片呢? JqPlot画图有点问题!! jquery,javascript日期验证
不知道行不行~~
<html>
<head>
<title></title>
</head>
<body>
<div style="height:960px;background:#330000;">teatteat</div>
<div id="t" style="height:24px;background:#000000;color:#ffffff;text-align:center;">teatteat</div>
<div style="height:960px;background:#333333;">teatteat</div>
<script type="text/javascript">
document.body.onscroll=function(){
if(document.body.scrollTop>=document.getElementById("t").offsetTop){
document.getElementById("t").style.position="absolute";
document.getElementById("t").style.top=document.body.scrollTop;
} else {
document.getElementById("t").style.position="static";
document.getElementById("t").style.top=document.body.scrollTop;
}
}
</script>
</body>
</html>随便写的,兼容可能有问题~~而且不流畅