Css 边框流动效果

源码实现 1

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div class="box">1234</div>
  <style>
     * {
      margin: 0;
      padding: 0;
    }
    .box {
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      width: 180px;
      height: 250px;
      border-radius: 20px;
      margin: 100px auto;
      background-color: #000;
      overflow: hidden;
      z-index: 0;
    }
    .box::before {
      content: '';
      position: absolute;
      z-index: -2;
      width: 120px;
      height: 120%;
      background: linear-gradient(#03fcc6, #ff0296);
      animation: rotates 3s linear infinite;
    }
    .box::after {
      content: '';
      position: absolute;
      z-index: -1;
      border-radius: 20px;
      inset: 5px;
      background-color: #FFF;
      /* background-color: #0e1538; */
    }
    @keyframes rotates {
      to {
        transform: rotate(360deg);
      }
    }
  </style>
</body>
</html>

源码实现2

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

<div class="card">
    <div class="bg"></div>
    <div class="blob"></div>
</div>
<style>
    .card {
        position: relative;
        width: 200px;
        height: 250px;
        border-radius: 14px;
        z-index: 1111;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        box-shadow: 20px 20px 60px #bebebe, -20px -20px 60px #ffffff;
    }

    .bg {
        position: absolute;
        top: 5px;
        left: 5px;
        width: 190px;
        height: 240px;
        z-index: 2;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(24px);
        border-radius: 10px;
        overflow: hidden;
        outline: 2px solid white;
    }

    .blob {
        position: absolute;
        z-index: 1;
        top: 50%;
        left: 50%;
        width: 150px;
        height: 150px;
        border-radius: 50%;
        background-color: #ff0000;
        opacity: 1;
        filter: blur(12px);
        animation: blob-bounce 3s infinite linear;
    }

    @keyframes blob-bounce {
        0% {
            transform: translate(-100%, -100%) translate3d(0, 0, 0);
        }
        25% {
            transform: translate(-100%, -100%) translate3d(100%, 0, 0);
        }
        50% {
            transform: translate(-100%, -100%) translate3d(100%, 100%, 0);
        }
        75% {
            transform: translate(-100%, -100%) translate3d(0, 100%, 0);
        }
        100% {
            transform: translate(-100%, -100%) translate3d(0, 0, 0);
        }
    }

</style>
</body>
</html>

封装成 vue 组件,让其成为一个容器:
 

<template>
  <div class="card animate">
    <div class="bg"></div>
    <div v-if="isActive" class="blob"></div>
    <slot></slot>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, watch } from 'vue';

export default defineComponent({
  name: 'AnimatedBorder',
  props: {
    isActive: {
      type: Boolean,
      required: true
    }
  },
});
</script>

<style scoped>
.card {
  position: relative;
  border-radius: 14px;
  z-index: 1111;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 20px 20px 60px #bebebe, -20px -20px 60px #ffffff;
}

.bg {
  position: absolute;
  top: 5px;
  left: 5px;
  width: calc(100% - 10px);
  height: calc(100% - 10px);
  z-index: 2;
  background: rgba(255, 255, 255);
  backdrop-filter: blur(24px);
  border-radius: 10px;
  overflow: hidden;
  outline: 2px solid white;
}

.blob {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: calc(100%);
  height: calc(100%);
  border-radius: 10%;
  background-color: #ff0000;
  opacity: 1;
  filter: blur(2px);
  animation: blob-bounce 3s infinite linear;
}

@keyframes blob-bounce {
  0% {
    transform: translate(-100%, -100%) translate3d(0, 0, 0);
  }
  25% {
    transform: translate(-100%, -100%) translate3d(100%, 0, 0);
  }
  50% {
    transform: translate(-100%, -100%) translate3d(100%, 100%, 0);
  }
  75% {
    transform: translate(-100%, -100%) translate3d(0, 100%, 0);
  }
  100% {
    transform: translate(-100%, -100%) translate3d(0, 0, 0);
  }
}

.animate .blob {
  animation: blob-bounce 3s infinite linear;
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值