@@ -26,7 +26,14 @@ import {
26
26
27
27
const props = extend ( {
28
28
tag : String ,
29
- moveClass : String
29
+ moveClass : String ,
30
+ origin : {
31
+ type : String ,
32
+ default : 'viewport' ,
33
+ validator ( val ) {
34
+ return [ 'viewport' , 'document' ] . indexOf ( val ) !== - 1
35
+ }
36
+ }
30
37
} , transitionProps )
31
38
32
39
delete props . mode
@@ -80,7 +87,7 @@ export default {
80
87
for ( let i = 0 ; i < prevChildren . length ; i ++ ) {
81
88
const c : VNode = prevChildren [ i ]
82
89
c . data . transition = transitionData
83
- c . data . pos = c . elm . getBoundingClientRect ( )
90
+ c . data . pos = this . getPosition ( c )
84
91
if ( map [ c . key ] ) {
85
92
kept . push ( c )
86
93
} else {
@@ -104,7 +111,7 @@ export default {
104
111
// we divide the work into three loops to avoid mixing DOM reads and writes
105
112
// in each iteration - which helps prevent layout thrashing.
106
113
children.forEach(callPendingCbs)
107
- children.forEach(recordPosition)
114
+ children.forEach(this. recordPosition)
108
115
children.forEach(applyTranslation)
109
116
110
117
// force reflow to put everything in position
@@ -157,6 +164,21 @@ export default {
157
164
const info : Object = getTransitionInfo ( clone )
158
165
this . $el . removeChild ( clone )
159
166
return ( this . _hasMove = info . hasTransform )
167
+ } ,
168
+ getPosition (c: VNode) {
169
+ const relativePos = c . elm . getBoundingClientRect ( )
170
+ const origin = this . origin
171
+ if ( origin === 'document' && document . documentElement ) {
172
+ const originPos = document . documentElement . getBoundingClientRect ( )
173
+ return {
174
+ top : relativePos . top - originPos . top ,
175
+ left : relativePos . left - originPos . left
176
+ }
177
+ }
178
+ return relativePos
179
+ } ,
180
+ recordPosition ( c : VNode ) {
181
+ c . data . newPos = this . getPosition ( c )
160
182
}
161
183
}
162
184
}
@@ -172,10 +194,6 @@ function callPendingCbs (c: VNode) {
172
194
}
173
195
}
174
196
175
- function recordPosition ( c : VNode ) {
176
- c . data . newPos = c . elm . getBoundingClientRect ( )
177
- }
178
-
179
197
function applyTranslation ( c : VNode ) {
180
198
const oldPos = c . data . pos
181
199
const newPos = c . data . newPos
0 commit comments