国产精品成人VA在线观看,亚洲日韩在线中文字幕综合,亚洲AV电影天堂男人的天堂,久久人人爽人人爽人人av东京热

News新聞

業(yè)界新聞動態(tài)、技術前沿
Who are we?

您的位置:首頁      JS/JQ/AJAX      拉動懸浮于頂部的JS控制代碼

拉動懸浮于頂部的JS控制代碼

標簽: 發(fā)布日期:2014-09-18 00:00:00 1296

有2個DIV,在未到達位置的時候css控制,一左一右。拉動到某位置的時候,需要他一直懸浮顯示,位置不變。代碼如下,其中有對瀏覽器判斷:

<script type="text/javascript">
var obj11 = document.getElementById("title_f4");
var top11 = getTop(obj11);
var obj10 = document.getElementById("left_row");
var isIE6 = /msie 6/i.test(navigator.userAgent);
window.onscroll = function(){
var bodyScrollTop = document.documentElement.scrollTop || document.body.scrollTop;
if (bodyScrollTop > top11){
obj11.style.position = (isIE6) ? "absolute" : "fixed";
obj10.style.position = (isIE6) ? "absolute" : "fixed";
obj11.style.top = (isIE6) ? bodyScrollTop + "px" : "0px";
obj10.style.top = (isIE6) ? bodyScrollTop + "px" : "0px";
obj10.style.margin = (document.body.clientWidth>1200) ? "0px 0px 0px 980px" : "0px 0px 0px 780px";
} else {
obj11.style.position = "static";
obj10.style.position = "static";
obj10.style.margin = "0px";
}
}
function getTop(e){
var offset = e.offsetTop;
if(e.offsetParent != null) offset += getTop(e.offsetParent);
return offset;
}
</script>