File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -2030,16 +2030,35 @@ export class GridStack {
2030
2030
// vars shared across all methods
2031
2031
let cellHeight : number , cellWidth : number ;
2032
2032
2033
+ // creates a reference element for tracking the right position after scaling
2034
+ const testEl = document . createElement ( 'div' ) ;
2035
+ Utils . addElStyles ( testEl , {
2036
+ opacity : '0' ,
2037
+ position : 'fixed' ,
2038
+ top : 0 + 'px' ,
2039
+ left : 0 + 'px' ,
2040
+ width : '1px' ,
2041
+ height : '1px' ,
2042
+ zIndex : '-999999' ,
2043
+ } ) ;
2044
+
2033
2045
let onDrag = ( event : DragEvent , el : GridItemHTMLElement , helper : GridItemHTMLElement ) => {
2034
2046
let node = el . gridstackNode ;
2035
2047
if ( ! node ) return ;
2036
2048
2037
2049
helper = helper || el ;
2050
+ helper . appendChild ( testEl ) ;
2051
+ const testElPosition = testEl . getBoundingClientRect ( ) ;
2052
+ helper . removeChild ( testEl ) ;
2053
+ const dragScale = {
2054
+ x : 1 / testElPosition . width ,
2055
+ y : 1 / testElPosition . height ,
2056
+ }
2038
2057
let parent = this . el . getBoundingClientRect ( ) ;
2039
2058
let { top, left} = helper . getBoundingClientRect ( ) ;
2040
2059
left -= parent . left ;
2041
2060
top -= parent . top ;
2042
- let ui : DDUIData = { position : { top, left} } ;
2061
+ let ui : DDUIData = { position : { top : top * dragScale . y , left : left * dragScale . x } } ;
2043
2062
2044
2063
if ( node . _temporaryRemoved ) {
2045
2064
node . x = Math . max ( 0 , Math . round ( left / cellWidth ) ) ;
You can’t perform that action at this time.
0 commit comments