diff options
| author | Pierre Vanduynslager <[email protected]> | 2017-03-18 21:24:54 -0400 |
|---|---|---|
| committer | Mark Otto <[email protected]> | 2017-03-18 18:24:54 -0700 |
| commit | 275821bbb081890ffe232d50d4778eb15bdb1d7b (patch) | |
| tree | 79d6a99cb89d449f75a26cf401a1dac6913eeda9 /js/src | |
| parent | f2f2e39a45039658c3ed7a39af834ca8dd802bdc (diff) | |
| download | bootstrap-275821bbb081890ffe232d50d4778eb15bdb1d7b.tar.xz bootstrap-275821bbb081890ffe232d50d4778eb15bdb1d7b.zip | |
HTMLElement.offset* by getBoundingClientRect() (#21788)
* Replace element.offet* by getBoundingClientRect()
* Use variable to store BoundingClientRect
* Fix cc issue...
Diffstat (limited to 'js/src')
| -rw-r--r-- | js/src/collapse.js | 4 | ||||
| -rw-r--r-- | js/src/modal.js | 2 | ||||
| -rw-r--r-- | js/src/scrollspy.js | 17 |
3 files changed, 12 insertions, 11 deletions
diff --git a/js/src/collapse.js b/js/src/collapse.js index 28c4493cc..ed3c064b1 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -211,10 +211,8 @@ const Collapse = (($) => { } const dimension = this._getDimension() - const offsetDimension = dimension === Dimension.WIDTH ? - 'offsetWidth' : 'offsetHeight' - this._element.style[dimension] = `${this._element[offsetDimension]}px` + this._element.style[dimension] = `${this._element.getBoundingClientRect()[dimension]}px` Util.reflow(this._element) diff --git a/js/src/modal.js b/js/src/modal.js index 213434f77..9263efd53 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -450,7 +450,7 @@ const Modal = (($) => { const scrollDiv = document.createElement('div') scrollDiv.className = ClassName.SCROLLBAR_MEASURER document.body.appendChild(scrollDiv) - const scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth + const scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth document.body.removeChild(scrollDiv) return scrollbarWidth } diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 66b6080c8..15541b8ff 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -133,12 +133,15 @@ const ScrollSpy = (($) => { target = $(targetSelector)[0] } - if (target && (target.offsetWidth || target.offsetHeight)) { - // todo (fat): remove sketch reliance on jQuery position/offset - return [ - $(target)[offsetMethod]().top + offsetBase, - targetSelector - ] + if (target) { + const targetBCR = target.getBoundingClientRect() + if (targetBCR.width || targetBCR.height) { + // todo (fat): remove sketch reliance on jQuery position/offset + return [ + $(target)[offsetMethod]().top + offsetBase, + targetSelector + ] + } } return null }) @@ -198,7 +201,7 @@ const ScrollSpy = (($) => { _getOffsetHeight() { return this._scrollElement === window ? - window.innerHeight : this._scrollElement.offsetHeight + window.innerHeight : this._scrollElement.getBoundingClientRect().height } _process() { |
