@@ -17,7 +17,32 @@ var rhorizontal = /left|center|right/,
17
17
rposition = / ^ \w + / ,
18
18
rpercent = / % $ / ,
19
19
center = "center" ,
20
- _position = $ . fn . position ;
20
+ _position = $ . fn . position ,
21
+ getScrollbarWidth = function ( ) {
22
+ var div = $ ( "<div style='display:block;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ) ,
23
+ innerDiv = div . children ( ) [ 0 ] ,
24
+ w1 , w2 ;
25
+ $ ( "body" ) . append ( div ) ;
26
+ w1 = innerDiv . offsetWidth ;
27
+ div . css ( "overflow" , "scroll" ) ;
28
+
29
+ w2 = innerDiv . offsetWidth ;
30
+
31
+ if ( w1 === w2 ) {
32
+ w2 = div [ 0 ] . clientWidth ;
33
+ }
34
+
35
+ div . remove ( ) ;
36
+
37
+ return w1 - w2 ;
38
+ } ,
39
+ getScrollInfo = function ( within ) {
40
+ var that = within [ 0 ] ,
41
+ scrollHeight = within . height ( ) < that . scrollHeight ,
42
+ scrollWidth = within . width ( ) < that . scrollWidth ,
43
+ scrollbarWidth = getScrollbarWidth ( ) ;
44
+ return { height : scrollHeight ? scrollbarWidth : 0 , width : scrollWidth ? scrollbarWidth : 0 } ;
45
+ } ;
21
46
22
47
$ . fn . position = function ( options ) {
23
48
if ( ! options || ! options . of ) {
@@ -114,16 +139,17 @@ $.fn.position = function( options ) {
114
139
basePosition . left += atOffset [ 0 ] ;
115
140
basePosition . top += atOffset [ 1 ] ;
116
141
117
- return this . each ( function ( ) {
142
+ return this . each ( function ( ) { console . log ( getScrollInfo ( within ) ) ;
118
143
var elem = $ ( this ) ,
119
144
elemWidth = elem . outerWidth ( ) ,
120
145
elemHeight = elem . outerHeight ( ) ,
121
146
marginLeft = parseInt ( $ . curCSS ( this , "marginLeft" , true ) ) || 0 ,
122
147
marginTop = parseInt ( $ . curCSS ( this , "marginTop" , true ) ) || 0 ,
148
+ scrollInfo = getScrollInfo ( within ) ,
123
149
collisionWidth = elemWidth + marginLeft +
124
- ( parseInt ( $ . curCSS ( this , "marginRight" , true ) ) || 0 ) ,
150
+ ( parseInt ( $ . curCSS ( this , "marginRight" , true ) ) || 0 ) + scrollInfo . width ,
125
151
collisionHeight = elemHeight + marginTop +
126
- ( parseInt ( $ . curCSS ( this , "marginBottom" , true ) ) || 0 ) ,
152
+ ( parseInt ( $ . curCSS ( this , "marginBottom" , true ) ) || 0 ) + scrollInfo . height ,
127
153
position = $ . extend ( { } , basePosition ) ,
128
154
myOffset = [
129
155
parseInt ( offsets . my [ 0 ] , 10 ) *
0 commit comments