Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit df57f66

Browse files
committed
use getBoundingClientRect() instead of offsetWidth & offsetHeight
1 parent d2747be commit df57f66

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/menu-container.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,18 @@ const MenuContainer = React.createClass({
4242
let scrollX = document.documentElement.scrollTop,
4343
scrollY = document.documentElement.scrollLeft,
4444
{ innerWidth, innerHeight } = window,
45-
{ offsetWidth, offsetHeight } = this.menu,
45+
rect = this.menu.getBoundingClientRect(),
4646
menuStyles = {
4747
top: y + scrollY,
4848
left: x + scrollX
4949
};
5050

51-
52-
if (y + offsetHeight > innerHeight) {
53-
menuStyles.top -= offsetHeight;
51+
if (y + rect.height > innerHeight) {
52+
menuStyles.top -= rect.height;
5453
}
5554

56-
if (x + offsetWidth > innerWidth) {
57-
menuStyles.left -= offsetWidth;
55+
if (x + rect.width > innerWidth) {
56+
menuStyles.left -= rect.width;
5857
}
5958

6059
return menuStyles;

0 commit comments

Comments
 (0)