8
8
import { DDResizableHandle } from './dd-resizable-handle' ;
9
9
import { DDBaseImplement , HTMLElementExtendOpt } from './dd-base-impl' ;
10
10
import { DDUtils } from './dd-utils' ;
11
+ import { Utils } from '../utils' ;
11
12
import { DDUIData , Rect , Size } from '../types' ;
12
13
13
14
// TODO: merge with DDDragOpt
@@ -37,6 +38,12 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
37
38
/** @internal */
38
39
private temporalRect : Rect ;
39
40
/** @internal */
41
+ private scrollY : number ;
42
+ /** @internal */
43
+ private scrolled : number ;
44
+ /** @internal */
45
+ private scrollEl : HTMLElement ;
46
+ /** @internal */
40
47
private startEvent : MouseEvent ;
41
48
/** @internal value saved in the same order as _originStyleProp[] */
42
49
private elOriginStyleVal : string [ ] ;
@@ -149,6 +156,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
149
156
/** @internal */
150
157
private _resizeStart ( event : MouseEvent ) : DDResizable {
151
158
this . originalRect = this . el . getBoundingClientRect ( ) ;
159
+ this . scrollEl = Utils . getScrollParent ( this . el ) ;
160
+ this . scrollY = this . scrollEl . scrollTop ;
152
161
this . startEvent = event ;
153
162
this . _setupHelper ( ) ;
154
163
this . _applyChange ( ) ;
@@ -163,6 +172,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
163
172
164
173
/** @internal */
165
174
private _resizing ( event : MouseEvent , dir : string ) : DDResizable {
175
+ this . scrolled = this . scrollEl . scrollTop - this . scrollY ;
166
176
this . temporalRect = this . _getChange ( event , dir ) ;
167
177
this . _applyChange ( ) ;
168
178
const ev = DDUtils . initEvent < MouseEvent > ( event , { type : 'resize' , target : this . el } ) ;
@@ -185,6 +195,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
185
195
delete this . startEvent ;
186
196
delete this . originalRect ;
187
197
delete this . temporalRect ;
198
+ delete this . scrollY ;
199
+ delete this . scrolled ;
188
200
return this ;
189
201
}
190
202
@@ -215,10 +227,11 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
215
227
const oEvent = this . startEvent ;
216
228
const newRect = { // Note: originalRect is a complex object, not a simple Rect, so copy out.
217
229
width : this . originalRect . width ,
218
- height : this . originalRect . height ,
230
+ height : this . originalRect . height + this . scrolled ,
219
231
left : this . originalRect . left ,
220
- top : this . originalRect . top
232
+ top : this . originalRect . top - this . scrolled
221
233
} ;
234
+
222
235
const offsetH = event . clientX - oEvent . clientX ;
223
236
const offsetV = event . clientY - oEvent . clientY ;
224
237
@@ -290,7 +303,13 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
290
303
private _ui = ( ) : DDUIData => {
291
304
const containmentEl = this . el . parentElement ;
292
305
const containmentRect = containmentEl . getBoundingClientRect ( ) ;
293
- const rect = this . temporalRect || this . originalRect ;
306
+ const newRect = { // Note: originalRect is a complex object, not a simple Rect, so copy out.
307
+ width : this . originalRect . width ,
308
+ height : this . originalRect . height + this . scrolled ,
309
+ left : this . originalRect . left ,
310
+ top : this . originalRect . top - this . scrolled
311
+ } ;
312
+ const rect = this . temporalRect || newRect ;
294
313
return {
295
314
position : {
296
315
left : rect . left - containmentRect . left ,
0 commit comments