From f5b126241dee516491fb9b9b52baa3bf368c0183 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Fri, 26 Jun 2015 13:55:09 -0600 Subject: [PATCH] Keep the element's original transform properties while and after dragging (fix the issue #92) --- draggabilly.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/draggabilly.js b/draggabilly.js index 9556a40..189a958 100644 --- a/draggabilly.js +++ b/draggabilly.js @@ -417,7 +417,9 @@ Draggabilly.prototype.dragEnd = function( event, pointer ) { this.isDragging = false; // use top left position when complete if ( transformProperty ) { - this.element.style[ transformProperty ] = ''; + var transform = this.element.style[ transformProperty ]; + transform = transform.replace( /translate(3d)?\(.*\)/, '' ); + this.element.style[ transformProperty ] = transform; this.setLeftTop(); } classie.remove( this.element, 'is-dragging' ); @@ -459,7 +461,9 @@ Draggabilly.prototype.setLeftTop = function() { Draggabilly.prototype.positionDrag = transformProperty ? function() { // position with transform - this.element.style[ transformProperty ] = translate( this.dragPoint.x, this.dragPoint.y ); + var transform = this.element.style[ transformProperty ]; + transform = transform.replace( /translate(3d)?\(.*\)/, '' ); + this.element.style[ transformProperty ] = transform + translate( this.dragPoint.x, this.dragPoint.y ); } : Draggabilly.prototype.setLeftTop; // ----- staticClick ----- // @@ -485,7 +489,9 @@ Draggabilly.prototype.destroy = function() { this.disable(); // reset styles if ( transformProperty ) { - this.element.style[ transformProperty ] = ''; + var transform = this.element.style[ transformProperty ]; + transform = transform.replace( /translate(3d)?\(.*\)/, '' ); + this.element.style[ transformProperty ] = transform; } this.element.style.left = ''; this.element.style.top = '';