css 流向线条动画特效 vue3+ts

纯css制作上下左右流动边框线条动画特效

一、三线箭头流向动画

需要自行准备两张箭头图片,并替换代码中的图片引入地址

组件代码:

<template>
  <div v-if="direction === 'vertical'" class="anmi-v">
    <div class="anmi-line-box-v">
      <div class="anmi-line-v"></div>
      <div class="anmi-line-v"></div>
      <div class="anmi-line-v"></div>
    </div>
    <div v-if="arrowShow" class="anmi-right-v"></div>
  </div>
  <div v-else class="anmi">
    <div class="anmi-line-box">
      <div class="anmi-line"></div>
      <div class="anmi-line"></div>
      <div class="anmi-line"></div>
    </div>
    <div v-if="arrowShow" class="anmi-right"></div>
  </div>
</template>

<script lang="ts" setup>
import { defineProps } from 'vue'

const props = defineProps({
  direction: {
    type: String,
    default: ''
  },
  arrowShow: {
    type: Boolean,
    default: false
  }
})
</script>

<style scoped>
.anmi-v {
  width: 16px;
  height: 100%;
  padding: 2px;
  background-color: rgba(75, 120, 150, 0.3);
  position: relative;
}
.anmi-line-box-v {
  height: 100%;
  display: flex;
  justify-content: space-around;
}
.anmi-line-v {
  width: 2px;
  height: 100%;
  background-color: rgba(64, 158, 255, 0.3);
  box-shadow: 0 3px 10px rgba(64, 158, 255, 0.5);
}
.anmi-right-v {
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 100%;
  background: url('@/assets/icons/svg/an-bottom.svg');
  background-size: 20px 40px;
  animation: dashedLineAnimationV 5s infinite linear;
}

@keyframes dashedLineAnimationV {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 0 100%;
  }
}
</style>
<style scoped>
.anmi {
  width: 100%;
  height: 16px;
  padding: 2px;
  background-color: rgba(75, 120, 150, 0.3);
  position: relative;
}
.anmi-line-box {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}
.anmi-line {
  width: 100%;
  height: 2px;
  background-color: rgba(64, 158, 255, 0.3);
  box-shadow: 0 3px 10px rgba(64, 158, 255, 0.5);
}
.anmi-right {
  position: absolute;
  top: 0;
  width: 100%;
  height: 20px;
  background: url('@/assets/icons/svg/an-right.svg');
  background-size: 40px 20px;
  animation: dashedLineAnimation 3s infinite linear;
}

@keyframes dashedLineAnimation {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 100% 0;
  }
}
</style>

两个方向(水平与垂直)引入示例:

<div style="width: 200px; height: 200px;">
   <arrow :arrow-show="true" />
   <arrow :arrow-show="true" :direction="'vertical'" />
</div>

组件封装了两个方向的流向动画,向右与向下,如需向左与向上的动画,可搭配 transform: rotate(180deg); 使用

二、流动拖尾动画

此动画与上面的动画相似,使用方法也一样,可参考上面的动画引入使用

组件代码

<template>
  <div v-if="direction === 'vertical'" class="anmi-v">
    <div class="anmi-line-box-v">
      <div v-if="arrowShow" class="point-v"></div>
    </div>
  </div>
  <div v-else class="anmi">
    <div class="anmi-line-box">
      <div v-if="arrowShow" class="point"></div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { defineProps } from 'vue'

const props = defineProps({
  direction: {
    type: String,
    default: ''
  },
  arrowShow: {
    type: Boolean,
    default: false
  }
})
</script>

<style scoped>
.anmi-v {
  width: 3px;
  height: 100%;
  background-color: #fff;
  position: relative;
}
.anmi-line-box-v {
  height: 100%;
  display: flex;
  justify-content: space-around;
  position: relative;
  border-radius: 10px;
  overflow-y: hidden;
}
.point-v {
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 50px;
  border-radius: 10px;
  background: linear-gradient(180deg, transparent 0, #409eff 70%);
  box-shadow: 0 3px 10px rgba(64, 158, 255, 0.8);
  animation: move-point-v infinite 5s linear;
}
@keyframes move-point-v {
  0% {
    top: -50px;
  }
  100% {
    top: calc(100% - 50px);
  }
}
</style>
<style scoped>
.anmi {
  width: 100%;
  height: 3px;
  background-color: #fff;
  position: relative;
}
.anmi-line-box {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  position: relative;
  border-radius: 10px;
  overflow-x: hidden;
}
.point {
  position: absolute;
  top: 0;
  left: 0;
  width: 50px;
  height: 3px;
  border-radius: 10px;
  background: linear-gradient(90deg, transparent 0, #409eff 70%);
  box-shadow: 0 3px 10px rgba(64, 158, 255, 0.8);
  animation: move-point infinite 5s linear;
}
@keyframes move-point {
  0% {
    left: -50px;
  }
  100% {
    left: calc(100% - 50px);
  }
}
</style>

三、虚线移动动画

<template>
  <div>
    <div class="dashed-line"></div>
  </div>
</template>

<style lang="scss" scoped>
.dashed-line {
  width: 160px;
  height: 3px;
  background: linear-gradient(to right, transparent 50%, #409eff 50%);
  background-size: 20px 3px;
  animation: dashedLineAnimation 3s infinite linear;
}
@keyframes lineFlow {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(100%);
  }
}

@keyframes dashedLineAnimation {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 100% 0;
  }
}
</style>

这里封装了向右的虚线动画,可参考上面两个示例封装更多功能

四、向右点与向右虚线

下面这段动画有兴趣的小伙伴可做参考

<template>
  <div>
    <div class="flow-view">
      <div class="top-left">
        <div class="line-view">
          <div class="line"></div>
          <div class="point"></div>
        </div>
     </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.flow-view {
  position: relative;
  width: 100%;
  height: 30rem;
  .top-left {
    position: absolute;
    left: 12rem;
    top: 1rem;
    width: 27rem;
  }

  .line-view {
    position: absolute;
    top: calc(1.5rem - 15px);
    left: 0rem;
    width: 100%;
    height: 30px;
    overflow: hidden;
    .line {
      position: absolute;
      top: 14px;
      left: 0;
      width: 100%;
      height: 3px;
      overflow: hidden;
      background: repeating-linear-gradient(
        90deg,
        transparent,
        transparent 4px,
        #eee 4px,
        #eee 10px
      );
      animation: move-line infinite 50000s linear;
    }
    .point {
      position: absolute;
      top: 0;
      left: 0;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background: rgba(64, 158, 255, 0.5);
      animation: move-point infinite 5s linear;
    }
    .point::before {
      content: "";
      position: absolute;
      top: 10px;
      left: 10px;
      width: 10px;
      height: 10px;
      opacity: 1;
      border-radius: 50%;
      background: #fff;
    }
  }
  @keyframes move-line {
    from {
      background-position: 0px;
    }
    to {
      background-position: 100000vw;
    }
  }
  @keyframes move-point {
    0% {
      left: 0;
    }
    100% {
      left: 100%;
    }
  }
}
</style>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值