|
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,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt |
37 | 38 | /** @internal */ |
38 | 39 | private temporalRect: Rect; |
39 | 40 | /** @internal */ |
| 41 | + private scrollY: number; |
| 42 | + /** @internal */ |
40 | 43 | private startEvent: MouseEvent; |
41 | 44 | /** @internal value saved in the same order as _originStyleProp[] */ |
42 | 45 | private elOriginStyleVal: string[]; |
@@ -152,6 +155,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt |
152 | 155 | /** @internal */ |
153 | 156 | private _resizeStart(event: MouseEvent): DDResizable { |
154 | 157 | this.originalRect = this.el.getBoundingClientRect(); |
| 158 | + const scrollEl = Utils.getScrollParent(this.el); |
| 159 | + this.scrollY = scrollEl === null ? 0 : scrollEl.scrollTop; |
155 | 160 | this.startEvent = event; |
156 | 161 | this._setupHelper(); |
157 | 162 | this._applyChange(); |
@@ -188,6 +193,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt |
188 | 193 | delete this.startEvent; |
189 | 194 | delete this.originalRect; |
190 | 195 | delete this.temporalRect; |
| 196 | + delete this.scrollY; |
191 | 197 | return this; |
192 | 198 | } |
193 | 199 |
|
@@ -216,12 +222,15 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt |
216 | 222 | /** @internal */ |
217 | 223 | private _getChange(event: MouseEvent, dir: string): Rect { |
218 | 224 | const oEvent = this.startEvent; |
| 225 | + const scrollEl = Utils.getScrollParent(this.el); |
| 226 | + const scrolled = scrollEl === null ? 0 : (scrollEl.scrollTop - this.scrollY); |
219 | 227 | const newRect = { // Note: originalRect is a complex object, not a simple Rect, so copy out. |
220 | 228 | width: this.originalRect.width, |
221 | | - height: this.originalRect.height, |
| 229 | + height: this.originalRect.height + scrolled, |
222 | 230 | left: this.originalRect.left, |
223 | | - top: this.originalRect.top |
| 231 | + top: this.originalRect.top - scrolled |
224 | 232 | }; |
| 233 | + |
225 | 234 | const offsetH = event.clientX - oEvent.clientX; |
226 | 235 | const offsetV = event.clientY - oEvent.clientY; |
227 | 236 |
|
@@ -291,9 +300,16 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt |
291 | 300 |
|
292 | 301 | /** @internal */ |
293 | 302 | private _ui = (): DDUIData => { |
294 | | - const containmentEl = this.el.parentElement; |
295 | | - const containmentRect = containmentEl.getBoundingClientRect(); |
296 | | - const rect = this.temporalRect || this.originalRect; |
| 303 | + const scrollEl = Utils.getScrollParent(this.el); |
| 304 | + const scrolled = scrollEl === null ? 0 : (scrollEl.scrollTop - this.scrollY); |
| 305 | + const containmentRect = this.el.parentElement.getBoundingClientRect(); |
| 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 + scrolled, |
| 309 | + left: this.originalRect.left, |
| 310 | + top: this.originalRect.top - scrolled |
| 311 | + }; |
| 312 | + const rect = this.temporalRect || newRect; |
297 | 313 | return { |
298 | 314 | position: { |
299 | 315 | left: rect.left - containmentRect.left, |
|
0 commit comments