function getAbsPoint(e) { var x = e.offsetLeft, y = e.offsetTop; while(e=e.offsetParent) { x += e.offsetLeft; y += e.offsetTop; } alert("x:"+x+","+"y:"+y); } 方法2: function getAbsPoint(obj) { var x,y; oRect = obj.getBoundingClientRect(); x=oRect.left y=oRect.top alert("("+x+","+y+")") } JS中獲得窗口屬性的方法 1。獲得屏幕的分辨率: screen.width screen.height 2。獲得窗口大小: document.body.clientWidth document.body.clientHeight 3。獲得窗口大小(包含Border、Scroll等元素) document.body.offsetWidth document.body.offsetHeight |
js獲取對象的絕對座標
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.