Skip to content

Commit

Permalink
fix spyglass out of window (#275)
Browse files Browse the repository at this point in the history
* fix spyglass out of window

* fix style eslint

* style fix eslint

Co-authored-by: Gautam Mishra <mishra.gautam96@gmail.com>
  • Loading branch information
mgautam98 and Gautam Mishra authored Mar 31, 2020
1 parent 7d74b5a commit bb58a8f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions components/spyglass/spyglass.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,14 @@ Spyglass.prototype.setPosition = function(pos) {
}
// check top edge
if (this.elt.offsetTop < 0) {
this.elt.style.left = `${pos.x - this.elt.offsetWidth*0.5}px`;
this.elt.style.left = `${Math.min(Math.max(0, pos.x - this.elt.offsetWidth*0.5),
this.elt.offsetParent.offsetWidth - this.elt.offsetWidth)}px`;
this.elt.style.top = `${pos.y + this.elt.offsetHeight*0.5}px`;
}
// check bottom edge
if (this.elt.offsetTop + this.elt.offsetHeight > this.elt.offsetParent.offsetHeight) {
this.elt.style.left = `${pos.x - this.elt.offsetWidth*0.5}px`;
this.elt.style.left = `${Math.min(Math.max(0, pos.x - this.elt.offsetWidth*0.5),
this.elt.offsetParent.offsetWidth - this.elt.offsetWidth)}px`;
this.elt.style.top = `${pos.y - this.elt.offsetHeight*1.5}px`;
}
};
Expand Down

0 comments on commit bb58a8f

Please sign in to comment.