项目原始demo,不改动
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
Ce dépôt est archivé. Vous pouvez voir les fichiers et le cloner, mais vous ne pouvez pas pousser ni ouvrir de ticket/demande d'ajout.
 
 
 
 

48 lignes
1.2 KiB

  1. function inserted(el, binding) {
  2. const modifiers = binding.modifiers || {};
  3. const value = binding.value;
  4. const {
  5. handler,
  6. options
  7. } = typeof value === 'object' ? value : {
  8. handler: value,
  9. options: {}
  10. };
  11. const observer = new IntersectionObserver((entries = [], observer) => {
  12. /* istanbul ignore if */
  13. if (!el._observe) return; // Just in case, should never fire
  14. // If is not quiet or has already been
  15. // initted, invoke the user callback
  16. if (handler && (!modifiers.quiet || el._observe.init)) {
  17. const isIntersecting = Boolean(entries.find(entry => entry.isIntersecting));
  18. handler(entries, observer, isIntersecting);
  19. } // If has already been initted and
  20. // has the once modifier, unbind
  21. if (el._observe.init && modifiers.once) unbind(el); // Otherwise, mark the observer as initted
  22. else el._observe.init = true;
  23. }, options);
  24. el._observe = {
  25. init: false,
  26. observer
  27. };
  28. observer.observe(el);
  29. }
  30. function unbind(el) {
  31. /* istanbul ignore if */
  32. if (!el._observe) return;
  33. el._observe.observer.unobserve(el);
  34. delete el._observe;
  35. }
  36. export const Intersect = {
  37. inserted,
  38. unbind
  39. };
  40. export default Intersect;
  41. //# sourceMappingURL=index.js.map