2023-07-07 19:22:30 +00:00
|
|
|
import { Directive } from "vue";
|
|
|
|
|
|
|
|
export default {
|
2023-07-23 13:31:28 +00:00
|
|
|
mounted(src, binding, vn) {
|
|
|
|
const fn = binding.value;
|
|
|
|
if (fn == null) return;
|
2023-07-07 19:22:30 +00:00
|
|
|
|
2023-07-23 13:31:28 +00:00
|
|
|
const observer = new IntersectionObserver((entries) => {
|
|
|
|
if (entries.some((entry) => entry.isIntersecting)) {
|
|
|
|
fn();
|
|
|
|
}
|
|
|
|
});
|
2023-07-07 19:22:30 +00:00
|
|
|
|
2023-07-23 13:31:28 +00:00
|
|
|
observer.observe(src);
|
2023-07-07 19:22:30 +00:00
|
|
|
|
2023-07-23 13:31:28 +00:00
|
|
|
src._observer_ = observer;
|
|
|
|
},
|
2023-07-07 19:22:30 +00:00
|
|
|
|
2023-07-23 13:31:28 +00:00
|
|
|
unmounted(src, binding, vn) {
|
|
|
|
if (src._observer_) src._observer_.disconnect();
|
|
|
|
},
|
2023-07-07 19:22:30 +00:00
|
|
|
} as Directive;
|