robot
最新文章(10)
這並不是一個創新
Tossug 2/9 SVG 加 XBL 分享
SVG and XBL No Widget
OpenSource 與嵌入式系統
Internet 的工人智慧
GCC Spec Files
Android Native code 的繪圖方法
Android Native code 不用 NDK
基於隱私的一種 DRM
Build Android SDK on FreeBSD
首頁
新編
最新留言
Entries RSS
重要關鍵字(10)
coding (120)
Python (93)
FreeBSD (71)
WEB (61)
雜記 (48)
URL (48)
hardware (46)
javascript (36)
Linux (31)
blog (30)
所有關鍵字
新增 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: