1
0

LoveVueThreeJS.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <script setup lang="ts">
  2. /// <reference types="vite-svg-loader" />
  3. import { gsap } from 'gsap'
  4. import { onMounted, ref } from 'vue'
  5. import Triangle from '../assets/triangle.svg'
  6. import SecondRow from '../assets/second-row.svg'
  7. import ThirdRow from '../assets/third-row.svg'
  8. const triangleRef = ref()
  9. const secondRowRef = ref()
  10. const thirdRowRef = ref()
  11. const tl2r = gsap.timeline()
  12. const tl3r = gsap.timeline()
  13. const heightOfSingleSvg = 150
  14. async function restartAnimation() {
  15. gsap.to(secondRowRef.value.$el, {
  16. duration: 1,
  17. y: 0,
  18. ease: 'elastic.out(0.7, 0.2)',
  19. })
  20. await gsap.to(thirdRowRef.value.$el, {
  21. delay: 0.65,
  22. duration: 1,
  23. y: 0,
  24. ease: 'steps(4)',
  25. })
  26. tl2r.restart()
  27. tl3r.restart()
  28. }
  29. onMounted(() => {
  30. tl2r.to(secondRowRef.value.$el, {
  31. delay: 1,
  32. duration: 2,
  33. y: -(8 * heightOfSingleSvg),
  34. ease: 'elastic.easeOut',
  35. })
  36. tl3r.to(thirdRowRef.value.$el, {
  37. delay: 1.25,
  38. duration: 2,
  39. y: -(12 * heightOfSingleSvg),
  40. ease: 'power1.out',
  41. })
  42. })
  43. </script>
  44. <template>
  45. <div
  46. class="grid items-center w-full min-w-370px -translate-x-20px md:translate-x-20px h-full scale-75"
  47. @click="restartAnimation"
  48. >
  49. <div class="grid grid-cols-3 gap-8 overflow-hidden h-93px">
  50. <Triangle ref="triangleRef" />
  51. <SecondRow ref="secondRowRef" />
  52. <ThirdRow ref="thirdRowRef" />
  53. </div>
  54. </div>
  55. </template>