@@ -26,7 +26,14 @@ import {
2626
2727const props = extend ( {
2828 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+ }
3037} , transitionProps )
3138
3239delete props . mode
@@ -80,7 +87,7 @@ export default {
8087 for ( let i = 0 ; i < prevChildren . length ; i ++ ) {
8188 const c : VNode = prevChildren [ i ]
8289 c . data . transition = transitionData
83- c . data . pos = c . elm . getBoundingClientRect ( )
90+ c . data . pos = this . getPosition ( c )
8491 if ( map [ c . key ] ) {
8592 kept . push ( c )
8693 } else {
@@ -104,7 +111,7 @@ export default {
104111 // we divide the work into three loops to avoid mixing DOM reads and writes
105112 // in each iteration - which helps prevent layout thrashing.
106113 children.forEach(callPendingCbs)
107- children.forEach(recordPosition)
114+ children.forEach(this. recordPosition)
108115 children.forEach(applyTranslation)
109116
110117 // force reflow to put everything in position
@@ -157,6 +164,21 @@ export default {
157164 const info : Object = getTransitionInfo ( clone )
158165 this . $el . removeChild ( clone )
159166 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 )
160182 }
161183 }
162184}
@@ -172,10 +194,6 @@ function callPendingCbs (c: VNode) {
172194 }
173195}
174196
175- function recordPosition ( c : VNode ) {
176- c . data . newPos = c . elm . getBoundingClientRect ( )
177- }
178-
179197function applyTranslation ( c : VNode ) {
180198 const oldPos = c . data . pos
181199 const newPos = c . data . newPos
0 commit comments