robot
最新文章(10)
Mqskit 和其它相關工具
CPython 的 GC 二、三事
寫 Mecurial Extension 是件快樂的事!
Mozilla 台灣辨公室徵人啟事
關於 Apple 的兩項專利
core dump 之前的 frame
怎麼發出 beep 聲?
先承認你要找的是奴才吧!
程式碼要清的多乾淨?
FreeBSD 的 Thread-Local Storage 實作
首頁
新編
最新留言
Entries RSS
重要關鍵字(10)
coding (122)
Python (93)
FreeBSD (71)
WEB (61)
URL (48)
hardware (46)
javascript (36)
Linux (34)
blog (30)
C++ (16)
所有關鍵字
新增 URL
計算 DOM 物件位置
by thinker
2 Columns
關鍵字:
WEB
javascript
原本在 MDC 找到,$javascript$ 可以用 o.clientLeft,取得 o 在網頁的位置(非螢幕位置)。後來發覺,這是 IE 特有,而 Gecko 還未 implement。想了半於,於是變通一下,自己計算。 {{{ function clientLeft(nod) { var x; x = nod.offsetLeft; if(nod.offsetParent) { x = x + clientLeft(nod.offsetParent); } return x; } }}} 配合使用 mousemove 的 event listener,就可以在 mouse 移動適當位置時,產生回應。例如: 換游標、換底色...等。 {{{ function resize_cursor_hdlr(evt) { var cur = evt.currentTarget; var sty, cl; cl = clientLeft(cur); if( evt.clientX > (cl + cur.scrollWidth - 10)) { sty = "e-resize"; } else { sty = "default"; } cur.style.cursor = sty; } o.addEventListener("mousemove", resize_cursor_hdlr, false); }}} 這$範例$能在 mouse 移動到 o 物件右側時,自動將游標換成 resize 的形式。 == 相關資料 == * http://developer.mozilla.org/en/docs/Gecko_DOM_Reference * http://www.w3.org/TR/CSS2/ui.html#cursor-props
最後更新時間: 2006-08-06 21:42:12 CST |
引用
查詢:
COMMENTS: