DIV导航冻结

15 篇文章 0 订阅
8 篇文章 0 订阅

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>滚动到顶部,锁定</title>
<style type="text/css">
.channelMove {
    overflow: hidden;
    position: fixed;
    top:0px;
    width: 300px;
    z-index: 200;
}
#channelHtml {
  
    display: block;
width:300px;
height:500px;
    margin-bottom: 10px;
border:  #000000 solid 1px;
}

</style>
</head>
<body>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<div id="dMark" class="clear" style="visibility:hidden;margin-top:-1px;"></div>
<div id="channelHtml">

</div>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</body>

<script type="text/javascript">
(function(){
$$ = function(id){return document.getElementById(id)}

function addClass(o,cn){var re = new RegExp("(\\s*|^)"+cn+"\\b","g");o.className +=o.className?(re.test(o.className)?"":" "+ cn):cn}
function removeClass(o,cn){var re = new RegExp("(\\s*|^)"+cn+"\\b","g");var sName = o.className;o.className = sName.replace(re,"")}

window.οnscrοll=window.οnresize=function(){
//document.documentElement.scrollTop  获取当前页面的滚动条纵坐标位置
//document.body.scrollTop 网页被卷去的高
//document.documentElement.clientTop  返回文档或元素的厚度
//document.documentElement.getBoundingClientRect.top 获取页面元素的顶部位置
var scrTop = document.body.scrollTop;
var offTop = $$("dMark").getBoundingClientRect().top+scrTop-document.documentElement.clientTop;
scrTop>offTop?addClass($$("channelHtml"),"channelMove"):removeClass($$("channelHtml"),"channelMove");
}
})();
</script>

</html>

 

 

原文链接

http://www.cnblogs.com/shoupifeng/archive/2012/08/16/2641967.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值