Created
September 5, 2017 08:02
-
-
Save uditalias/e4605d7f457cffd188879e3c690d20bb to your computer and use it in GitHub Desktop.
ADHD module
This file contains 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
const ADHDHelpers = (function () { | |
let module = { | |
scrollTop: 0, | |
isDisabled: false, | |
shouldDisplayScrollbar: false, | |
disablePageScroll: function () { | |
if (this.isDisabled) { | |
return; | |
} | |
let $body = document.body; | |
this.isDisabled = true; | |
this.shouldDisplayScrollbar = $body.scrollHeight > window.innerHeight; | |
window.requestAnimationFrame(() => { | |
this.scrollTop = $body.scrollTop; | |
$body.style.position = 'fixed'; | |
$body.style.top = `-${this.scrollTop}px`; | |
$body.style.width = '100%'; | |
if (this.shouldDisplayScrollbar) { | |
$body.style.overflowY = 'scroll'; | |
} | |
}); | |
}, | |
enablePageScroll: function () { | |
if (!this.isDisabled) { | |
return; | |
} | |
this.isDisabled = false; | |
let $body = document.body; | |
window.requestAnimationFrame(() => { | |
$body.style.position = ''; | |
$body.style.top = ''; | |
$body.style.width = ''; | |
$body.scrollTop = this.scrollTop; | |
this.scrollTop = 0; | |
if(this.shouldDisplayScrollbar) { | |
$body.style.overflowY = ''; | |
} | |
}); | |
} | |
}; | |
return { | |
disablePageScroll: module.disablePageScroll.bind(module), | |
enablePageScroll: module.enablePageScroll.bind(module) | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment