相關關鍵詞
關于我們
最新文章
- 拉動懸浮于頂部的JS控制代碼 》
- 在JavaScript中構建ArrayList示例代碼
- js使用for循環(huán)及if語句判斷多個一樣的name
- JavaScript中判斷原生函數(shù)檢查function是否是原生代碼
- jQuery CSS()方法改變現(xiàn)有的CSS樣式表
- JavaScript中判斷原生函數(shù)檢查function是否是原生代碼
- jQuery動畫高級用法(上)——詳解animation中的.queue()函數(shù)
- python小技巧之批量抓取美女圖片
- JS中offsetTop、clientTop、scrollTop、offsetTop各屬性介紹
- JS獲取瀏覽器窗口大小 獲取屏幕,瀏覽器,網頁高度寬度
拉動懸浮于頂部的JS控制代碼
有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>