1.js獲取div元素
clientHeight 獲取對象的高度,不計算任何邊距、邊框、滾動條,但包括該對象的補白。
clientLeft 獲取 offsetLeft 屬性和客戶區域的實際左邊之間的距離。
clientTop 獲取 offsetTop 屬性和客戶區域的實際頂端之間的距離。
clientWidth 獲取對象的寬度,不計算任何邊距、邊框、滾動條,但包括該對象的補白。
offsetHeight 獲取對象相對於版面或由父坐標 offsetParent 屬性指定的父坐標的高度。
offsetLeft 獲取對象相對於版面或由 offsetParent 屬性指定的父坐標的計算左側位置。
offsetParent 獲取定義對象 offsetTop 和 offsetLeft 屬性的容器對象的引用。
offsetTop 獲取對象相對於版面或由 offsetTop 屬性指定的父坐標的計算頂端位置。
offsetWidth 獲取對象相對於版面或由父坐標 offsetParent 屬性指定的父坐標的寬度。
offsetX 設置或獲取鼠標指針位置相對於觸發事件的對象的 x 坐標。
offsetY 設置或獲取鼠標指針位置相對於觸發事件的對象的 y 坐標。
clientX,clientY 鼠標當前相對於網頁的位置,當鼠標位於頁面左上角時clientX=0, clientY=0
screenX, screenY是相對於用戶顯示器的位置
網頁可見區域寬: document.body.clientWidth
網頁可見區域高: document.body.clientHeight
網頁可見區域寬: document.body.offsetWidth (包括邊線的寬)
網頁可見區域高: document.body.offsetHeight (包括邊線的寬)
網頁正文全文寬: document.body.scrollWidth
網頁正文全文高: document.body.scrollHeight
網頁被卷去的高: document.body.scrollTop
網頁被卷去的左: document.body.scrollLeft
網頁正文部分上: window.screenTop
網頁正文部分左: window.screenLeft
屏幕分辨率的高: window.screen.height
屏幕分辨率的寬: window.screen.width
屏幕可用工作區高度: window.screen.availHeight
屏幕可用工作區寬度:window.screen.availWidth
舉例:
判斷鼠標是否在此div上面
var div = document.getElementById("dialog_div"); var divx1 = div.offsetLeft; var divy1 = div.offsetTop; var divx2 = div.offsetLeft + div.offsetWidth; var divy2 = div.offsetTop + div.offsetHeight; var x=event.clientX; var y=event.clientY; //鼠標在此div內則返回 if( x > divx1 && x < divx2 && y >divy1 && y < divy2){ return true; }