mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-09 17:02:38 +00:00
Fixed #4682 - Animate directive renamed as AnimateOnScroll
This commit is contained in:
parent
42c27d9469
commit
b52e8c4f0d
17 changed files with 118 additions and 117 deletions
60
components/lib/animateonscroll/AnimateOnScroll.js
Normal file
60
components/lib/animateonscroll/AnimateOnScroll.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
import { DomHandler } from 'primevue/utils';
|
||||
import BaseAnimateOnScroll from './BaseAnimateOnScroll';
|
||||
|
||||
const AnimateOnScroll = BaseAnimateOnScroll.extend('animateonscroll', {
|
||||
mounted(el, binding) {
|
||||
el.setAttribute('data-pd-animateonscroll', true);
|
||||
!this.isUnstyled() && DomHandler.addClass(el, 'p-animate');
|
||||
|
||||
this.bindIntersectionObserver(el, binding);
|
||||
},
|
||||
unmounted(el) {
|
||||
this.unbindIntersectionObserver(el);
|
||||
clearTimeout(this.timeout);
|
||||
},
|
||||
timeout: null,
|
||||
observer: null,
|
||||
methods: {
|
||||
bindIntersectionObserver(el, binding) {
|
||||
const options = {
|
||||
root: null,
|
||||
rootMargin: '0px',
|
||||
threshold: 1.0
|
||||
};
|
||||
|
||||
this.observer = new IntersectionObserver((element) => this.isVisible(element, el, binding), options);
|
||||
this.observer.observe(el);
|
||||
},
|
||||
isVisible(target, el, binding) {
|
||||
const [intersectionObserverEntry] = target;
|
||||
|
||||
intersectionObserverEntry.isIntersecting ? this.enter(el, binding) : this.leave(el, binding);
|
||||
},
|
||||
enter(el, binding) {
|
||||
el.style.visibility = 'visible';
|
||||
DomHandler.addMultipleClasses(el, binding.value.enterClass);
|
||||
|
||||
binding.modifiers.once && this.unbindIntersectionObserver(el);
|
||||
},
|
||||
leave(el, binding) {
|
||||
DomHandler.removeClass(el, binding.value.enterClass);
|
||||
|
||||
if (binding.value.leaveClass) {
|
||||
DomHandler.addMultipleClasses(el, binding.value.leaveClass);
|
||||
}
|
||||
|
||||
const animationDuration = el.style.animationDuration || 500;
|
||||
|
||||
this.timeout = setTimeout(() => {
|
||||
el.style.visibility = 'hidden';
|
||||
}, animationDuration);
|
||||
},
|
||||
unbindIntersectionObserver(el) {
|
||||
if (this.observer) {
|
||||
this.observer.unobserve(el);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default AnimateOnScroll;
|
Loading…
Add table
Add a link
Reference in a new issue