Skip to content

Commit

Permalink
fix(FEC-10351): possible to drag floating player out of screen bounda…
Browse files Browse the repository at this point in the history
…ries (#13)

Restricted floating player position to within window boundaries
  • Loading branch information
RoyBregman authored Jul 29, 2020
1 parent f8e4df8 commit 65b56c1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/visibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,12 @@ class Visibility extends BasePlugin {
// set the element's new position
if (floatingContainer) {
const boundClientRect = floatingContainer.getBoundingClientRect();
floatingContainer.style.top = boundClientRect.top - parseInt(floatingContainer.style.marginTop) - deltaMousePosY + 'px';
floatingContainer.style.left = boundClientRect.left - parseInt(floatingContainer.style.marginLeft) - deltaMousePosX + 'px';
let top = Math.max(boundClientRect.top - parseInt(floatingContainer.style.marginTop) - deltaMousePosY, 0); // bound top
top = Math.min(top, window.innerHeight - boundClientRect.height - this.config.floating.marginY * 2); //bound bottom
floatingContainer.style.top = top + 'px';
let left = Math.max(boundClientRect.left - parseInt(floatingContainer.style.marginLeft) - deltaMousePosX, 0); //bound left
left = Math.min(left, window.innerWidth - boundClientRect.width - this.config.floating.marginX * 2); //bound right
floatingContainer.style.left = left + 'px';
}

// handle throttling to avoid performance issues on dragging
Expand Down

0 comments on commit 65b56c1

Please sign in to comment.