primevue-mirror/apps/showcase/components/template/TemplateFeaturesAnimationIn...

102 lines
3.4 KiB
Vue
Raw Permalink Normal View History

2024-04-08 05:20:44 +00:00
<template>
2024-06-26 09:26:19 +00:00
<div ref="animationInlineRef" class="w-full py-8 rounded-xl bg-surface-50 dark:bg-surface-800 relative flex flex-col items-center justify-center">
<div class="hidden sm:flex items-center gap-0.5 xl:gap-1 rounded-full border border-surface p-1 w-[90%] bg-surface-0 dark:bg-surface-900">
2024-04-08 05:20:44 +00:00
<template v-for="(data, index) in inlineFeaturesData" :key="index">
2024-06-26 09:26:19 +00:00
<button
@click="handleBtnClick(data.id)"
@mouseenter="enterCardArea(data.id)"
@mouseleave="leaveCardArea"
:class="`flex-1 py-1 px-1 lg:px-2 rounded-full text-surface-900 dark:text-surface-0 border-none outline-none text-xs font-medium transition-all hover:bg-surface-200 dark:hover:bg-surface-700 cursor-pointer ${
data.id === selectedID ? 'bg-surface-200 dark:bg-surface-700' : 'bg-transparent'
}`"
>
2024-04-08 05:20:44 +00:00
{{ data.title }}
</button>
</template>
</div>
2024-06-26 09:26:19 +00:00
<div class="w-[90%] h-fit overflow-hidden relative flex mt-5 rounded-lg shadow-[0px_0px_48px_0px_rgba(0,0,0,0.08)]">
<img class="max-h-96 w-full h-auto object-cover object-top flex" :src="inlineFeaturesData[selectedID - 1].src" alt="Animation Inline Feature Image" />
2024-04-08 05:20:44 +00:00
</div>
</div>
</template>
<script>
export default {
props: {
inlineFeaturesData: {
type: null,
default: null
},
parentHandleClick: {
type: null,
default: null
},
parentHandleHover: {
type: null,
default: null
},
parentID: {
type: null,
default: null
},
inlineSeconds: {
type: Number,
default: 1000
}
},
observer: null,
timeout: null,
data() {
return {
selectedID: 1,
hoveredID: null,
intervalId: null
};
},
mounted() {
this.observer = new IntersectionObserver(([entry]) => {
clearTimeout(this.timeout);
if (entry.isIntersecting) {
this.timeout = setTimeout(
() => {
this.startInterval();
this.observer.unobserve(this.$el);
},
{ threshold: 0.2 }
);
}
});
this.observer.observe(this.$el);
},
beforeUnmount() {
this.$el && this.observer?.unobserve(this.$el);
clearInterval(this.intervalId);
},
methods: {
handleClick(id) {
this.selectedID = id;
},
handleBtnClick(id) {
this.handleClick(id);
this.parentHandleClick(this.parentID);
clearInterval(this.intervalId);
},
startInterval() {
this.intervalId = setInterval(() => {
this.selectedID = this.selectedID === this.inlineFeaturesData.length ? 1 : this.selectedID + 1;
}, this.inlineSeconds);
},
enterCardArea(id) {
this.hoveredID = id;
this.parentHandleHover(this.parentID, 'onMouseEnter');
},
leaveCardArea() {
this.hoveredID = null;
this.parentHandleHover(this.parentID, 'onMouseLeave');
}
}
};
</script>