Last active
May 29, 2017 01:07
-
-
Save usrbowe/2b6663ea9dfb73514255da0a277d634a to your computer and use it in GitHub Desktop.
bug in intersection observer polyfill
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>IntersectionObserver</title> | |
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=IntersectionObserver&min=false"></script> | |
<style> | |
html, body { | |
padding: 0; | |
margin: 0; | |
height: 100%; | |
} | |
body { | |
overflow-x: hidden; | |
} | |
.section { | |
height: 50vh; | |
background-color: #ccc; | |
} | |
.section:nth-child(odd) { | |
background-color: #ddd; | |
} | |
#box { | |
width: 400px; | |
height: 150px; | |
background-color: rebeccapurple; | |
} | |
</style> | |
</head> | |
<body> | |
<section class="section"></section> | |
<section class="section"></section> | |
<section class="section"> | |
<!-- observed element --> | |
<div id="box"></div> | |
</section> | |
<section class="section"></section> | |
<script> | |
const iO = new IntersectionObserver((observedElements) => { | |
if (observedElements[0].intersectionRatio > 0) { | |
console.log('observe the element', observedElements[0].intersectionRatio); | |
} | |
}, { | |
threshold: [0.5], | |
}); | |
iO.observe(document.getElementById('box')); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment