blob: 87faf611f09b3267c82da9db65bb884bdb05d433 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
$$plugins.define('intersecting', function (element, options) {
const el = document.querySelector(options.target);
const observer = new window.IntersectionObserver(([entry]) => {
const intersectionRatio = entry.intersectionRatio.toFixed(2);
if (entry.isIntersecting) {
element.classList.add("sticky");
} else {
element.classList.remove("sticky");
}
}, {
root: null,
rootMargin: '-30% 0px -70%',
threshold: 0
})
observer.observe(el)
});
|