1 |
|
2 | // .sticky { position: sticky; top: -1px; }
|
3 | // .sticky.is-stuck { color: red; }
|
4 |
|
5 | /* global El, IntersectionObserver */
|
6 | El.$b.sticky = function sticky(el) {
|
7 | ;(sticky._ob || (sticky._ob = new IntersectionObserver(function(entries) {
|
8 | entries.forEach(function(entry) {
|
9 | El.cls(entry.target, "is-stuck", entry.intersectionRatio < 1)
|
10 | })
|
11 | }, { threshold: 1 }))).observe(el)
|
12 | El.cls(el, "sticky")
|
13 | }
|
14 |
|
15 |
|