During the past few monthes, I have been writing components like dropdown, tooltip and popover. And I found myself running into a few edge cases again and again. In order to tackle such positioning issue, I think we need to systemactically know what are those positioning API available on web in the first place and then find a way to deal the problems.
Positioning is all about relativity and boundary. An element is placed to either the window
, its view port
or a target
element. And we always need to consider the relationship between the content and the boundry of those three above based on practical business logics.
window
pageYOffset
window.scrollY
pageXOffset
window.scrollX
innerHeight
innerWidth
target
getBoundingClientRect
There are some interesting Redux/React related repos worthy to dive into. react-tunnel React components and decorators for putting context-like values into context and pulling them out as props...