|
|
@ -1,6 +1,6 @@ |
|
|
|
<template> |
|
|
|
<div class="header_line_container"> |
|
|
|
<h2 class="title">{{ title }}</h2> |
|
|
|
<div class="header_line_container" ref="el"> |
|
|
|
<h2 class="title" ref="titleRef">{{ title }}</h2> |
|
|
|
<p class="line"></p> |
|
|
|
<p class="desc" v-if="line1"> |
|
|
|
{{ line1 }} |
|
|
@ -12,6 +12,9 @@ |
|
|
|
</template> |
|
|
|
|
|
|
|
<script setup> |
|
|
|
import { ref, onMounted } from 'vue' |
|
|
|
const el = ref(null) |
|
|
|
const titleRef = ref(null) |
|
|
|
const props = defineProps({ |
|
|
|
title: { |
|
|
|
type: String, |
|
|
@ -23,6 +26,33 @@ const props = defineProps({ |
|
|
|
type: String, |
|
|
|
}, |
|
|
|
}) |
|
|
|
onMounted(() => { |
|
|
|
const observer = new IntersectionObserver(entries => { |
|
|
|
entries.forEach(entry => { |
|
|
|
if (entry.isIntersecting) { |
|
|
|
animateCSS('bounce') |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
observer.observe(el.value) |
|
|
|
}) |
|
|
|
const animateCSS = (animation, prefix = 'animate__') => |
|
|
|
// We create a Promise and return it |
|
|
|
new Promise((resolve, reject) => { |
|
|
|
const animationName = `${prefix}${animation}` |
|
|
|
const node = titleRef.value |
|
|
|
|
|
|
|
node.classList.add(`${prefix}animated`, animationName) |
|
|
|
|
|
|
|
// When the animation ends, we clean the classes and resolve the Promise |
|
|
|
function handleAnimationEnd(event) { |
|
|
|
event.stopPropagation() |
|
|
|
node.classList.remove(`${prefix}animated`, animationName) |
|
|
|
resolve('Animation ended') |
|
|
|
} |
|
|
|
|
|
|
|
node.addEventListener('animationend', handleAnimationEnd, { once: true }) |
|
|
|
}) |
|
|
|
</script> |
|
|
|
|
|
|
|
<style lang="scss" scoped> |
|
|
|