Skip to content

Instantly share code, notes, and snippets.

@jakeboxer
Created May 22, 2015 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakeboxer/fd0c43fa4382c8d38307 to your computer and use it in GitHub Desktop.
Save jakeboxer/fd0c43fa4382c8d38307 to your computer and use it in GitHub Desktop.
$ ->
sidebar = document.querySelector('.js-org-migration-settings-sidebar')
if sidebar?
sidebarRect = sidebar.getBoundingClientRect()
parentRect = sidebar.parentNode.getBoundingClientRect()
stickySidebarLeft = parentRect.width + parentRect.left - sidebarRect.width
stickySidebarTop = 16
stickyThreshold = sidebarRect.top + window.pageYOffset - stickySidebarTop
originalPosition = sidebar.style.position;
originalTop = sidebar.style.top;
originalLeft = sidebar.style.left;
originalWidth = sidebar.style.width;
window.addEventListener 'scroll', ->
if window.pageYOffset >= stickyThreshold
sidebar.style.position = 'fixed'
sidebar.style.top = stickySidebarTop + 'px'
sidebar.style.left = stickySidebarLeft + 'px'
sidebar.style.width = '250px'
else
sidebar.style.position = originalPosition
sidebar.style.top = originalTop
sidebar.style.left = originalLeft
sidebar.style.width = originalWidth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment