(value, elem, scrollTop = getScrollTop(), viewportHeight = getViewportHeight())
| 132 | * @returns {String} value - Absolute value. |
| 133 | */ |
| 134 | const relativeToAbsoluteValue = function(value, elem, scrollTop = getScrollTop(), viewportHeight = getViewportHeight()) { |
| 135 | |
| 136 | const elemSize = elem.getBoundingClientRect() |
| 137 | |
| 138 | const elemAnchor = value.match(/^[a-z]+/)[0] |
| 139 | const viewportAnchor = value.match(/[a-z]+$/)[0] |
| 140 | |
| 141 | let y = 0 |
| 142 | |
| 143 | if (viewportAnchor === 'top') y -= 0 |
| 144 | if (viewportAnchor === 'middle') y -= viewportHeight / 2 |
| 145 | if (viewportAnchor === 'bottom') y -= viewportHeight |
| 146 | |
| 147 | if (elemAnchor === 'top') y += (elemSize.top + scrollTop) |
| 148 | if (elemAnchor === 'middle') y += (elemSize.top + scrollTop) + elemSize.height / 2 |
| 149 | if (elemAnchor === 'bottom') y += (elemSize.top + scrollTop) + elemSize.height |
| 150 | |
| 151 | return `${ y }px` |
| 152 | |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Validates data and sets defaults for undefined properties. |
no test coverage detected