Last active
November 23, 2017 19:19
-
-
Save alersenkevich/44e61dd7b4ed59821e178c5f0663b0f5 to your computer and use it in GitHub Desktop.
simple function for grabbing content inside div with hidden overflow
This file contains hidden or 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
function grabStage(e) { | |
const stage = document.getElementById('large-stage-container') | |
const { layerX: endX, layerY: endY } = e | |
const { x: startX, y: startY } = window.grabCoords // this coords are coords from the event.layer(X-Y) and we got them while first mousedown on stage | |
const distance = { x: Math.abs(endX - startX), y: Math.abs(endY - startY) } | |
if (!distance.x && !distance.y) return | |
const direction = { | |
x: (endX < startX) ? 'right' : 'left', | |
y: (endY < startY) ? 'down' : 'up', | |
} | |
const toX = (direction.x === 'right') ? stage.scrollLeft + distance.x : stage.scrollLeft - distance.x | |
const toY = (direction.y === 'down') ? stage.scrollTop + distance.y : stage.scrollTop - distance.y | |
stage.scrollTo(toX, toY) | |
} |
function grabStage(e, options, domElement) {...}
(e) => grabStage(e, {}, document.getElementById('large-stage-container'))
или можно возращать из ф-ции координаты, и где-то снаружи делать scrollTo
thanks man
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
вау