diff --git a/resources/js/components/fieldtypes/VideoFieldtype.vue b/resources/js/components/fieldtypes/VideoFieldtype.vue index ade6098a87..848a08d4fb 100644 --- a/resources/js/components/fieldtypes/VideoFieldtype.vue +++ b/resources/js/components/fieldtypes/VideoFieldtype.vue @@ -16,10 +16,12 @@ {{ __('statamic::validation.url') }} @@ -30,6 +32,13 @@ import Fieldtype from './Fieldtype.vue'; export default { mixins: [Fieldtype], + data() { + return { + isVisible: false, + observer: null, + }; + }, + computed: { shouldShowPreview() { return !this.isInvalid && (this.isEmbeddable || this.isVideo); @@ -87,5 +96,29 @@ export default { return !this.isEmbeddable && isVideo; }, }, + + mounted() { + this.observer = new IntersectionObserver( + (entries) => { + entries.forEach((entry) => { + if (entry.isIntersecting && entry.intersectionRatio > 0) { + this.isVisible = true; + this.observer.disconnect(); + } + }); + }, + { threshold: 0.01 } + ); + + if (this.$el) { + this.observer.observe(this.$el); + } + }, + + beforeUnmount() { + if (this.observer) { + this.observer.disconnect(); + } + }, };