@@ -135,6 +135,9 @@ $.widget("ui.draggable", $.ui.mouse, {
135
135
left : this . offset . left - this . margins . left
136
136
} ;
137
137
138
+ //Reset scroll cache
139
+ this . offset . scroll = false ;
140
+
138
141
$ . extend ( this . offset , {
139
142
click : { //Where the click happened, relative to the element
140
143
left : event . pageX - this . offset . left ,
@@ -433,18 +436,23 @@ $.widget("ui.draggable", $.ui.mouse, {
433
436
var mod = d === "absolute" ? 1 : - 1 ,
434
437
scroll = this . cssPosition === "absolute" && ! ( this . scrollParent [ 0 ] !== document && $ . contains ( this . scrollParent [ 0 ] , this . offsetParent [ 0 ] ) ) ? this . offsetParent : this . scrollParent , scrollIsRootNode = ( / ( h t m l | b o d y ) / i) . test ( scroll [ 0 ] . tagName ) ;
435
438
439
+ //Cache the scroll
440
+ if ( ! this . offset . scroll ) {
441
+ this . offset . scroll = { top : scroll . scrollTop ( ) , left : scroll . scrollLeft ( ) } ;
442
+ }
443
+
436
444
return {
437
445
top : (
438
446
pos . top + // The absolute mouse position
439
447
this . offset . relative . top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
440
448
this . offset . parent . top * mod - // The offsetParent's offset without borders (offset + border)
441
- ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollTop ( ) : ( scrollIsRootNode ? 0 : scroll . scrollTop ( ) ) ) * mod )
449
+ ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollTop ( ) : ( scrollIsRootNode ? 0 : this . offset . scroll . top ) ) * mod )
442
450
) ,
443
451
left : (
444
452
pos . left + // The absolute mouse position
445
453
this . offset . relative . left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
446
454
this . offset . parent . left * mod - // The offsetParent's offset without borders (offset + border)
447
- ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollLeft ( ) : scrollIsRootNode ? 0 : scroll . scrollLeft ( ) ) * mod )
455
+ ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollLeft ( ) : scrollIsRootNode ? 0 : this . offset . scroll . left ) * mod )
448
456
)
449
457
} ;
450
458
@@ -459,6 +467,11 @@ $.widget("ui.draggable", $.ui.mouse, {
459
467
pageX = event . pageX ,
460
468
pageY = event . pageY ;
461
469
470
+ //Cache the scroll
471
+ if ( ! this . offset . scroll ) {
472
+ this . offset . scroll = { top : scroll . scrollTop ( ) , left : scroll . scrollLeft ( ) } ;
473
+ }
474
+
462
475
/*
463
476
* - Position constraining -
464
477
* Constrain the position to a mix of grid, containment.
@@ -508,14 +521,14 @@ $.widget("ui.draggable", $.ui.mouse, {
508
521
this . offset . click . top - // Click offset (relative to the element)
509
522
this . offset . relative . top - // Only for relative positioned nodes: Relative offset from element to offset parent
510
523
this . offset . parent . top + // The offsetParent's offset without borders (offset + border)
511
- ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollTop ( ) : ( scrollIsRootNode ? 0 : scroll . scrollTop ( ) ) ) )
524
+ ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollTop ( ) : ( scrollIsRootNode ? 0 : this . offset . scroll . top ) ) )
512
525
) ,
513
526
left : (
514
527
pageX - // The absolute mouse position
515
528
this . offset . click . left - // Click offset (relative to the element)
516
529
this . offset . relative . left - // Only for relative positioned nodes: Relative offset from element to offset parent
517
530
this . offset . parent . left + // The offsetParent's offset without borders (offset + border)
518
- ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollLeft ( ) : scrollIsRootNode ? 0 : scroll . scrollLeft ( ) ) )
531
+ ( ( this . cssPosition === "fixed" ? - this . scrollParent . scrollLeft ( ) : scrollIsRootNode ? 0 : this . offset . scroll . left ) )
519
532
)
520
533
} ;
521
534
0 commit comments