Skip to content

Commit a2a2182

Browse files
committed
Update utils.js
1 parent f5a49c5 commit a2a2182

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

utils.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ let setStorage = (item, value) => {
439439

440440
// move element to element (when origin element has 'position: fixed')
441441

442-
let moveElToEl = (originEl, destEl, boundryMargin = null, boundryEl = null) => {
442+
let moveElToEl = (originEl, destEl, boundryMargin = null, margin = null, boundryEl = null) => {
443443

444444
// get bounding box of dest element
445445
const rect = destEl.getBoundingClientRect(),
@@ -484,13 +484,24 @@ let moveElToEl = (originEl, destEl, boundryMargin = null, boundryEl = null) => {
484484

485485
let destTop = rect.top + destHeight,
486486
destLeft = rect.left;
487+
488+
489+
// add margin
490+
if (margin) {
491+
492+
if (margin.top) destTop = destTop + margin.top;
493+
494+
if (margin.left) destLeft = destLeft + margin.left;
495+
496+
}
497+
487498

488499
// check if element is outside window
489500
if (maxTop < destTop) destTop = maxTop;
490501
if (minTop > destTop) destTop = minTop;
491502
if (maxLeft < destLeft) destLeft = maxLeft;
492503
if (minLeft > destLeft) destLeft = minLeft;
493-
504+
494505

495506
originEl.style.top = destTop + 'px';
496507
originEl.style.left = destLeft + 'px';

0 commit comments

Comments
 (0)