-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This supports internal scrollbars and numbers for padding
- Loading branch information
1 parent
6dbd7e2
commit bbaaaa8
Showing
7 changed files
with
83 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* a handful of shared functions and constants | ||
*/ | ||
|
||
export const minArrowPadding = 5; | ||
export const bodyPadding = 10; | ||
export const noArrowDistance = 3; | ||
|
||
/** | ||
* cross browser scroll positions | ||
*/ | ||
export function getScrollTop() { | ||
return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; | ||
} | ||
|
||
export function getScrollLeft() { | ||
return window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0; | ||
} | ||
|
||
export function getArrowSpacing(props) { | ||
const defaultArrowSpacing = props.arrow ? props.arrowSize : noArrowDistance; | ||
return typeof props.distance === 'number' ? props.distance : defaultArrowSpacing; | ||
} | ||
|
||
/** | ||
* get first ancestor that might scroll | ||
*/ | ||
export function getScrollParent(element) { | ||
const style = getComputedStyle(element); | ||
let scrollParent = window; | ||
|
||
if (style.position !== 'fixed') { | ||
let parent = element.parentElement; | ||
|
||
while (parent) { | ||
const parentStyle = getComputedStyle(parent); | ||
|
||
if (/(auto|scroll)/.test(parentStyle.overflow + parentStyle.overflowY + parentStyle.overflowX)) { | ||
scrollParent = parent; | ||
parent = undefined; | ||
} else { | ||
parent = parent.parentElement; | ||
} | ||
} | ||
} | ||
|
||
return scrollParent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters