intersection_observer.js 401 B

12345678910111213141516
  1. export default {
  2. template: '<div style="position: absolute"></div>',
  3. mounted() {
  4. this.interval = setInterval(() => {
  5. const rect = this.$el.getBoundingClientRect();
  6. if (rect.bottom > -window.innerHeight && rect.top < 2 * window.innerHeight) {
  7. this.$emit("intersection");
  8. }
  9. }, 100);
  10. },
  11. methods: {
  12. stop() {
  13. clearInterval(this.interval);
  14. },
  15. },
  16. };