Last active
February 8, 2017 15:47
-
-
Save blivesta/1e8645ac20eb9f6b8e641f63236061c6 to your computer and use it in GitHub Desktop.
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
<style> | |
.section { | |
height: 100vh; | |
} | |
[data-doorman] { | |
display: inline-block; | |
visibility: hidden; | |
} | |
</style> | |
<div id="section1" class="section"> | |
<div data-doorman>section1</div> | |
</div> | |
<div id="section2" class="section"> | |
<div data-doorman>section2</div> | |
</div> | |
<div id="section3" class="section"> | |
<div data-doorman>section3</div> | |
</div> | |
<script src="https://unpkg.com/scrollmonitor@1.2.2"></script> | |
<script src="https://unpkg.com/doorman-effect/umd/doorman.min.js"></script> | |
<script> | |
const sections = [ | |
document.getElementById('section1'), | |
document.getElementById('section2'), | |
document.getElementById('section3') | |
] | |
Array.prototype.forEach.call(sections, (section) => { | |
const elementWatcher = scrollMonitor.create(section, -200) | |
elementWatcher.enterViewport(() => { | |
const elements = section.querySelectorAll('[data-doorman]') | |
Array.prototype.forEach.call(elements, (el) => { | |
const doorman = new Doorman(el) | |
doorman.start() | |
}) | |
elementWatcher.destroy() | |
}) | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment