X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F02_dom%2F04_XBoxModel.js;h=0a5c3429e2d788b7c38cbf3c618db29468b97b32;hb=3256f11c856314a1425b8459b9d000a88caf8258;hp=f7fa20bd7fd11a9e01175dce4162c77b4b3ae4ae;hpb=dd02887497fa95f13d112b7fc2e5e7aefd0ffb08;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/02_dom/04_XBoxModel.js b/0.6.x/js/02_dom/04_XBoxModel.js index f7fa20b..0a5c342 100644 --- a/0.6.x/js/02_dom/04_XBoxModel.js +++ b/0.6.x/js/02_dom/04_XBoxModel.js @@ -26,6 +26,20 @@ X_ViewPort.listenOnce( X_TEMP.SYSTEM_EVENT_INIT, function(){ 'box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;-o-box-sizing:border-box;-ms-box-sizing:border-box;' ) .width() === 10; }; + + /* + * 古い Gekco、 Presto、 WebKit では影がレイアウトに影響します。たとえば、width が 100% のボックスに外向きの box-shadow を指定すると、横スクロールバーが表示されてしまいます。 + * TODO boxShadow が有効な要素に対して offsetWidth 等の補正(?) + */ + if( X_Node_CSS_Support[ 'boxShadow' ] && + node.cssText( + X_Node_CSS_uncamelize( X_Node_CSS_VENDER_PREFIX[ 'boxShadow' ] ) + ':10px 10px 0 0 #000;width:10px;' + ).width() !== 10 + ){ + console.log( node.cssText() + node.width() ); + X_Node_CSS_Support[ 'boxShadowLayoutBug' ] = true; + }; + // padding // border // margin @@ -37,6 +51,7 @@ X_ViewPort.listenOnce( X_TEMP.SYSTEM_EVENT_INIT, function(){ .firstChild().cssText( 'position:absolute;top:8px;left:8px;margin:16px;border:32px solid #666;padding:64px;' ) .y(); + node.cssText( '' ).empty(); }); @@ -285,17 +300,19 @@ Node.prototype.offset = function( /* xnodeParent */ ){ console.log( 'xnode.offset() : no parent' ); return { x : 0, y : 0 }; }; - X_Node_updateTimerID && X_Node_startUpdate(); + if( !this._root ){ console.log( 'xnode.offset() : not belong tree.' ); return { x : 0, y : 0 }; }; - if( this._state & X_Node_State.DISPLAY_NONE ) return 0; + if( this._state & X_Node_State.DISPLAY_NONE ) return { x : 0, y : 0 }; if( X.Doc.body === this || X.Doc.html === this ){ return { x : 0, y : 0 }; }; + X_Node_updateTimerID && X_Node_startUpdate(); + if( X_UA_DOM.W3C ){ elm = this._rawObject; } else @@ -305,6 +322,8 @@ Node.prototype.offset = function( /* xnodeParent */ ){ }; + return X_Node_getPosition( elm ); + while( elm && elm !== document.body ){ x += elm.offsetLeft; y += elm.offsetTop; @@ -312,3 +331,62 @@ Node.prototype.offset = function( /* xnodeParent */ ){ }; return { x : x, y : y }; }; + +// エレメントの座標取得 ~スクロール要素~ +// http://n-yagi.0r2.net/script/2009/06/post_14.html + +//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ +// エレメントの絶対座標を得たい +//------------------------------------------------------------------------------ +// 座標取得 +var X_Node_getPosition = + document.documentElement && document.documentElement.getBoundingClientRect ? + function( el ){ + var pos = el.getBoundingClientRect(), + html = document.documentElement, + body = document.body; + return { x:(pos.left + (body.scrollLeft||html.scrollLeft) - html.clientLeft) + , y:(pos.top + (body.scrollTop||html.scrollTop) - html.clientTop) }; + } : + X.UA.Opera < 10 ? + function( el ){ + var ex = 0; + var ey = 0; + do + { + ex += el.offsetLeft; + ey += el.offsetTop; + } + while( el = el.offsetParent ); + // + return {x:ex,y:ey}; + } : + function(target) + { + var ex = 0; + var ey = 0; + // + var el = target; + var bd = document.body; + + do + { + ex += el.offsetLeft || 0; + ey += el.offsetTop || 0; + } + while( el = el.offsetParent ); + // 要素内スクロール対応 + el = target; + do + { + ex -= el.scrollLeft || 0; + ey -= el.scrollTop || 0; + el = el.parentNode; + } + while( el!=bd ); + // + return {x:ex,y:ey}; + }; + +//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ +