Skip to content

Instantly share code, notes, and snippets.

@alersenkevich
Last active November 23, 2017 19:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alersenkevich/44e61dd7b4ed59821e178c5f0663b0f5 to your computer and use it in GitHub Desktop.
Save alersenkevich/44e61dd7b4ed59821e178c5f0663b0f5 to your computer and use it in GitHub Desktop.
simple function for grabbing content inside div with hidden overflow
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)
}
@dmitryshelomanov
Copy link

вау

@SergProduction
Copy link

SergProduction commented Nov 22, 2017

function grabStage(e, options, domElement) {...}
(e) => grabStage(e, {}, document.getElementById('large-stage-container'))

или можно возращать из ф-ции координаты, и где-то снаружи делать scrollTo

@alersenkevich
Copy link
Author

thanks man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment