Last active
August 2, 2018 09:15
-
-
Save hyeonseok/242f198688cc7494713c to your computer and use it in GitHub Desktop.
Swap window scroll from main content to modal window, and vise versa.
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
// Needs to be clean up. | |
var mainContent = document.getElementById('main'); | |
var open = function (target) { | |
var closeButton = target.querySelector('p.button button'); | |
mainContent.style.top = -1 * document.body.scrollTop + 'px'; | |
mainContent.style.position = 'fixed'; | |
target.setAttribute('aria-hidden', 'false'); | |
document.body.scrollTop = 0; | |
closeButton.addEventListener('click', close); | |
}; | |
var close = function (event) { | |
var element = event.currentTarget; | |
var target = element.parentNode.parentNode; | |
var scrollTop = parseInt(mainContent.style.top.replace('px', '')) * -1; | |
mainContent.style.position = 'static'; | |
mainContent.style.top = 0; | |
target.setAttribute('aria-hidden', 'true'); | |
document.body.scrollTop = scrollTop; | |
element.removeEventListener('click', close); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment