Vue3 + TypeScript +动画,实现动态登陆页面

动态切换登陆和注册,动画效果

文章目录

前言

这是基于Vue3 + TypeScript + animation + Element-UI Plus + Element-UI icon结合实现的动态帅气的登陆页面

一、HTML

html 复制代码
<template>
  <div class="container">
    <div class="sign-box">
      <!-- 登陆功能 -->
      <div
        class="sign-in-box"
        :class="{ 'sign-in-bg': !show, 'sign-bg-left': isShow }">
        <h2
          style="
            font-size: 30px;
            text-align: center;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
              Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue',
              sans-serif;
          ">
          Sign In
        </h2>
        <div style="display: flex; margin-top: 20px">
          <el-input
            v-model="login_Obj.username"
            style="width: 240px; height: 40px"
            :prefix-icon="User"
            placeholder="Please username" />
        </div>
        <div style="display: flex; margin-top: 20px">
          <el-input
            v-model="login_Obj.password"
            style="width: 240px; height: 40px"
            :prefix-icon="Lock"
            placeholder="Please password" />
        </div>
        <div style="text-align: center; margin-top: 20px">
          <el-button type="primary" size="default" @click="login">
            Sign In
          </el-button>
        </div>
      </div>
      <!-- 注册页面 -->
      <div
        class="sign-up-box"
        :class="{ 'sign-bg-right': !show, 'sign-up-bg': isShow }">
        <h1
          style="
            font-size: 30px;
            text-align: center;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
              Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue',
              sans-serif;
          ">
          Sign Up
        </h1>
        <div style="display: flex; margin-top: 20px">
          <el-input
            v-model="register_Obj.email"
            style="width: 240px; height: 40px"
            :prefix-icon="Message"
            placeholder="Please email" />
        </div>
        <div style="display: flex; margin-top: 20px">
          <el-input
            v-model="register_Obj.username"
            style="width: 240px; height: 40px"
            :prefix-icon="User"
            placeholder="Please username" />
        </div>
        <div style="display: flex; margin-top: 20px">
          <el-input
            v-model="register_Obj.password"
            style="width: 240px; height: 40px"
            :prefix-icon="Lock"
            placeholder="Please password" />
        </div>
        <div style="text-align: center; margin-top: 20px">
          <el-button type="primary" size="default" @click="register">
            Sign Up
          </el-button>
        </div>
      </div>
      <!-- 按钮区域 -->
      <div class="sign-in-btn" :class="{ 'sign-bt-left': !show }">
        <button @click="signIn">Sign In(登陆按钮功能)</button>
      </div>
      <div
        class="sign-up-btn"
        :class="{ 'sign-up-btn-left': !show, 'sign-bt-right': isShow }">
        <button @click="signUp">Sign Up(注册按钮功能)</button>
      </div>
    </div>
  </div>
</template>

二、JavaScript

javascript 复制代码
import { User, Lock, Message } from '@element-plus/icons-vue'
import { reactive, ref } from 'vue'
let show = ref(true)
let isShow = ref(false)
// 账号密码
let login_Obj = reactive({
  username: '',
  password: '',
})
let register_Obj = reactive({
  email: '',
  username: '',
  password: '',
})

const login = () => {
  console.log(login_Obj)
}

const register = () => {
  console.log(register_Obj)
}

const signUp = () => {
  show.value = !show.value
  isShow.value = false
}
const signIn = () => {
  show.value = true
  isShow.value = !isShow.value
}

三、CSS

c 复制代码
.container {
  width: 100%;
  height: 100vh;
  background: url('./img/bgimg3.jpg') no-repeat;
  background-position: center center;
  background-size: cover;
  display: flex;
  justify-content: center;
  align-items: center;
  .sign-box {
    display: flex;
    width: 754px;
    height: 450px;
    border-radius: 10px;
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.3);
    .sign-up-box {
      position: absolute;
      opacity: 0;
      z-index: 0;
      background-color: #e9e9e9;
      width: 50%;
      height: 100%;
      padding: 90px 70px;
    }
    .sign-in-box {
      position: absolute;
      background-color: #e9e9e9;
      width: 50%;
      height: 100%;
      z-index: 1;
      padding: 90px 70px;
    }

    .sign-up-btn {
      position: absolute;
      left: 50%;
      width: 50%;
      height: 100%;
      text-align: center;
      padding: 200px 70px;
      button {
        background-color: #409eff;
        border-radius: 50px;
        padding: 20px;
        color: #ffffff;
      }
    }

    .sign-in-btn {
      position: absolute;
      opacity: 0;
      z-index: 0;
      left: 50%;
      width: 50%;
      height: 100%;
      text-align: center;
      padding: 200px 70px;
      button {
        background-color: #409eff;
        border-radius: 50px;
        padding: 20px;
        color: #ffffff;
      }
    }

    .sign-in-bg {
      z-index: 0;
      opacity: 0;
    }
    .sign-up-bg {
      z-index: 0;
      opacity: 0;
    }
    .sign-up-btn-left {
      z-index: 0;
      opacity: 0;
    }

    .sign-bt-left {
      animation: show 1s forwards;
    }
    .sign-bt-right {
      animation: show3 1s forwards;
    }
    .sign-bg-right {
      animation: show1 1s forwards;
    }
    .sign-bg-left {
      animation: show4 1s forwards;
    }
  }
  @keyframes show {
    0% {
      left: 50%;
      opacity: 0;
      z-index: 0;
    }
    100% {
      left: 0;
      opacity: 1;
      z-index: 5;
    }
  }
  @keyframes show1 {
    0% {
      left: 0;
      opacity: 1;
      z-index: 0;
    }
    100% {
      left: 50%;
      opacity: 1;
      z-index: 5;
    }
  }
  @keyframes show3 {
    0% {
      left: 0%;
      opacity: 1;
      z-index: 0;
    }
    100% {
      left: 50%;
      opacity: 1;
      z-index: 5;
    }
  }

  @keyframes show4 {
    0% {
      left: 50%;
      opacity: 1;
      z-index: 0;
    }
    100% {
      left: 0;
      opacity: 1;
      z-index: 5;
    }
  }
}
相关推荐
To_OC34 分钟前
别再串行写 await 了,Promise.all 才是并行请求的正确打开方式
前端·javascript·promise
To_OC1 小时前
LC 17 电话号码的字母组合:我的回溯算法,就是从这道题开窍的
javascript·算法·leetcode
vipbic1 小时前
中后台越做越乱后,我用插件化把它救回来了
前端·vue.js
Hyyy1 小时前
Computer Use 适合做什么,不适合做什么——一次真实使用后的思考
前端
小和尚同志2 小时前
前端 AI 单元测试思考与落地
前端·人工智能·aigc
invicinble3 小时前
c端系统,其实更像一个信息展示平台
前端
你怎么知道我是队长3 小时前
JavaScript的变量和数据类型介绍
开发语言·javascript·ecmascript
李姆斯3 小时前
管理是否可以被完全量化
前端·产品经理·团队管理
名字还没想好☜4 小时前
Next.js 中间件实战:鉴权、重定向与 A/B 分流
开发语言·前端·javascript·中间件·react·next.js
广州灵眸科技有限公司4 小时前
瑞芯微RV1126B开发板(EASY-EAI-PI2) INI文件操作
java·前端·javascript·网络·人工智能