1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 18:39:51 +02:00

use pageXOffset instead of scrollX for ie support (#664)

This commit is contained in:
Tyler Johnson
2017-03-18 18:01:44 -06:00
committed by Ian Storm Taylor
parent 5ce7d165aa
commit 0f59ef6447

View File

@@ -13,17 +13,17 @@ function scrollToSelection(selection) {
const backward = isBackward(selection)
const range = selection.getRangeAt(0)
const rect = range.getBoundingClientRect()
const { innerWidth, innerHeight, scrollY, scrollX } = window
const top = (backward ? rect.top : rect.bottom) + scrollY
const left = (backward ? rect.left : rect.right) + scrollX
const { innerWidth, innerHeight, pageYOffset, pageXOffset } = window
const top = (backward ? rect.top : rect.bottom) + pageYOffset
const left = (backward ? rect.left : rect.right) + pageXOffset
const x = left < scrollX || innerWidth + scrollX < left
const x = left < pageXOffset || innerWidth + pageXOffset < left
? left - innerWidth / 2
: scrollX
: pageXOffset
const y = top < scrollY || innerHeight + scrollY < top
const y = top < pageYOffset || innerHeight + pageYOffset < top
? top - innerHeight / 2
: scrollY
: pageYOffset
window.scrollTo(x, y)
}