利用GSAP简单实现首页的过渡动画

https://mock.ezcomezgo.com/gsap-demo-1/

利用GSAP简单实现首页的过渡动画插图
<template>
  <div class="header">
    <div class="title">Title</div>
    <div class="nav">
      <div class="nav-item">nav-item-1</div>
      <div class="nav-item">nav-item-2</div>
      <div class="nav-item">nav-item-3</div>
      <div class="nav-item">nav-item-4</div>
      <div class="nav-item">nav-item-5</div>
    </div>
    <div class="menu">Menu</div>
  </div>
  <div class="body">
    <div class="content">
      <div class="title">Title</div>
      <div class="desc">Lorem ipsum dolor sit amet consectetur adipisicing elit. Vero eos repellendus aliquam facilis
        provident. Similique sapiente, harum obcaecati molestias inventore accusantium eum aliquid nihil suscipit
        molestiae laboriosam, aliquam modi ipsum.</div>
    </div>
    <div class="bgc"></div>
  </div>
</template>

<style>
:root {
  --bgc: #1c073e;
  --header-high: 80px;
  --body-heigh: calc(100vh - var(--header-high));
  --menu-width: 400px;
  --padding-left: 40px;
}

html,
body {
  all: unset;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-content: center;
  color: #fff;
  background-color: var(--bgc);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  text-decoration: none;
  list-style: none;
  -webkit-user-drag: none;
  user-select: none;
}

.header,
.body {
  width: 100vw;
  padding: 0px var(--padding-left);
  overflow: hidden;
}

.header {
  height: var(--header-high);
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.body {
  height: var(--body-heigh);
}

.header .title {
  font-size: 24px;
}

.header .title,
.header .nav {
  display: flex;
  justify-content: center;
  align-items: center;
  transition: .3s;
}

.header .nav {
  flex-direction: row;
  height: calc(var(--header-high) / 2);
}

.header .nav .nav-item {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 100px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.header .nav .nav-item::before {
  transition: .3s;
  position: absolute;
  content: '';
  height: 5px;
  background-color: rgb(255, 255, 255);
  bottom: 0px;
  width: 0px;
  border-radius: 3px;
}

.header .nav .nav-item:hover::before {
  width: 80%;
}

.header .menu {
  display: none;
  transition: .3s;
}

.body {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  position: relative;
}

.body .content {
  position: relative;
  z-index: 2;
  opacity: 1;
  width: 700px;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: flex-start;
  flex-wrap: wrap;
}

.body .content .title,
.body .content .desc {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 22px;
}

.body .content .title {
  font-size: 30px;
  font-weight: bold;
}

.body .bgc {
  width: 100%;
  height: 100%;
  background-image: url('./assets/elefant.svg');
  background-size: 600px 600px;
  background-position: 300px;
  background-repeat: no-repeat;
}

@media screen and (max-width: 900px) {
  .header .menu {
    display: block;
  }

  .header .nav {
    width: 100%;
    display: none;
  }
}
</style>
<script setup>
import gsap from 'gsap'
import { onMounted } from 'vue';
onMounted(() => {
  const tween = gsap.timeline({ delay: 0.5 })
  tween.from('.header', {
    duration: 0.5,
    ease: 'power2',
    y: -500,
  })
  tween.from('.body .content', {
    duration: 0.8,
    ease: 'power2',
    y: 200,
    opacity: 0
  })
  tween.from('.body .bgc', {
    duration: 1.2,
    ease: 'power2',
    x: 400,
    opacity: 0
  })
})
</script>