Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f073756

Browse files
authored
Merge pull request gridstack#1967 from adumesny/master
restore animation when dragging items
2 parents f1b15e3 + a666b24 commit f073756

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Change log
7171
## 5.0.0-dev (TBD)
7272
* add `GridStack.registerEngine()` to let user use their own custom layout engine subclass. Thank you [Thomas] for sponsoring it.
7373
* grid option `minWidth` is now `oneColumnSize` to make it clearer, but old field will still work (JS only) for a while
74+
* fix [#1966](https://github.com/gridstack/gridstack.js/issues/1966) restore animation when dragging items
7475
* updated jqueryui to latest v1.13.1
7576

7677
## 5.0.0 (2022-01-10)

src/h5/dd-draggable.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
5353
protected helperContainment: HTMLElement;
5454
/** @internal #1541 can't have {passive: true} on Safari as otherwise it reverts animate back to old location on drop */
5555
protected static dragEventListenerOption = true; // DDUtils.isEventSupportPassiveOption ? { capture: true, passive: true } : true;
56-
/** @internal */
56+
/** @internal properties we change during dragging, and restore back */
5757
protected static originStyleProp = ['transition', 'pointerEvents', 'position',
5858
'left', 'top', 'opacity', 'zIndex', 'width', 'height', 'willChange', 'min-width'];
5959

@@ -232,19 +232,15 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
232232

233233
/** @internal */
234234
protected _removeHelperStyle(): DDDraggable {
235+
let node = (this.helper as GridItemHTMLElement)?.gridstackNode;
235236
// don't bother restoring styles if we're gonna remove anyway...
236-
let node = this.helper ? (this.helper as GridItemHTMLElement).gridstackNode : undefined;
237237
if (this.dragElementOriginStyle && (!node || !node._isAboutToRemove)) {
238-
DDDraggable.originStyleProp.forEach(prop => {
239-
this.helper.style[prop] = this.dragElementOriginStyle[prop] || null;
240-
});
238+
let helper = this.helper;
239+
DDDraggable.originStyleProp.forEach(prop => helper.style[prop] = this.dragElementOriginStyle[prop] || null);
241240
// show up instantly otherwise we animate to off the grid when switching back to 'absolute' from 'fixed'
242-
this.helper.style.transition = 'none';
243-
setTimeout(() => {
244-
if (this.helper) {
245-
this.helper.style.transition = this.dragElementOriginStyle['transition']; // recover animation
246-
}
247-
}, 0);
241+
helper.style.transition = 'none';
242+
let transition = this.dragElementOriginStyle['transition'] || null;
243+
setTimeout(() => helper.style.transition = transition, 0); // recover animation from saved vars
248244
}
249245
delete this.dragElementOriginStyle;
250246
return this;

0 commit comments

Comments
 (0)