Skip to content

Instantly share code, notes, and snippets.

@lukasborawski
Last active October 2, 2017 14:45
Show Gist options
  • Save lukasborawski/cd387c101b5dc2b7c9a6f73c88cd8ee6 to your computer and use it in GitHub Desktop.
Save lukasborawski/cd387c101b5dc2b7c9a6f73c88cd8ee6 to your computer and use it in GitHub Desktop.
Scroll to Element for Angular 2
scrollToBottom () {
function offset(el:any) {
let rect = el.getBoundingClientRect(),
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
scrollTop = window.pageYOffset || document.documentElement.scrollTop;
return { top: rect.top + scrollTop, left: rect.left + scrollLeft }
}
let content = document.getElementById('content')
if (content) {
let offsetTop = offset(content).top
window.scrollTo(0, offsetTop)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment