简单的进度条组件

本文介绍如何创建并使用一个名为scrollBar.vue的子组件,该组件在前端项目中作为进度条展示滚动进度。通过在父组件中引入这个子组件,可以轻松实现页面滚动时的视觉反馈效果。

scrollBar.vue 子组件

<template>
  <!-- 进度条组件 -->
  <div class="scrollBar" :style="{ width: scrollWidth }">
    <div class="scrollBar_process" :style="{ width: width + '%' }">
      <div
        class="process"
        :class="[
          backgroundColor == 0
            ? 'process_ative'
            : backgroundColor == 1
            ? 'process_ative2'
            : backgroundColor == 2
            ? 'process_ative3'
            : '',
        ]"
      ></div>
      <div
        class="dot"
        v-if="width != 0"
        :class="[
          backgroundColor == 0
            ? 'dot_ative'
            : backgroundColor == 1
            ? 'dot_ative2'
            : backgroundColor == 2
            ? 'dot_ative3'
            : '',
        ]"
      ></div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    height: {
      type: String,
      default() {
        return "8px";
      },
    },
    width: {
      type: String,
      default() {
        return "80";
      },
    },
    scrollWidth: {
      type: String,
      default() {
        return "360px";
      },
    },
    backgroundColor: {
      type: Number,
      default() {
        return 0;
      },
    },
  },
  data() {
    return {};
  },
  watch: {
    width(e) {
      console.log(e);
    },
  },
  created() {},
  mounted() {},
  methods: {},
};
</script>

<style scoped lang='scss'>
.scrollBar {
  height: 2px;
  background: rgba(2, 77, 182, 0.7);
  // opacity: 0.33;
  position: relative;
  .scrollBar_process {
    position: absolute;
    top: -1px;
    width: 80%;
    height: 4px;
    display: flex;
    .process {
      width: 100%;
      height: 100%;
      background: linear-gradient(
        90deg,
        rgba(37, 166, 255, 0.3) 0%,
        #25a6ff 100%
      );
    }
    .process_ative {
      background: linear-gradient(
        90deg,
        rgba(250, 102, 102, 0.19) 0%,
        #ff6767 100%
      );
      opacity: 0.99;
    }
    .process_ative2 {
      background: linear-gradient(
        90deg,
        rgba(255, 230, 81, 0.14) 0%,
        #fdde45 100%
      );
      opacity: 0.99;
    }
    .process_ative3 {
      background: linear-gradient(
        90deg,
        rgba(148, 255, 83, 0.09) 0%,
        #73ff25 100%
      );
      opacity: 0.99;
    }
    .dot {
      margin-top: -2px;
      box-shadow: 0px 0px 2px 6px rgba(35, 157, 242, 0.3);
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background-color: #24a1f9;
    }
    .dot_ative {
      background-color: rgba(255, 103, 103, 1);
      box-shadow: 0px 0px 2px 6px rgba(255, 103, 103, 0.3);
    }
    .dot_ative2 {
      background-color: rgba(241, 212, 71, 1);
      box-shadow: 0px 0px 2px 6px rgba(241, 212, 71, 0.3);
    }
    .dot_ative3 {
      background-color: rgba(97, 229, 77, 1);
      box-shadow: 0px 0px 2px 6px rgba(97, 229, 77, 0.3);
    }
  }
}
</style>

父组件引入使用:

 <scroll-bar
          :width="(item.num / Percentage) * 100 + ''"
          :backgroundColor="index"
          :scrollWidth="'350px'"
        ></scroll-bar>

// scrollWidth:宽度
// backgroundColor 进度条颜色 参数 1,2,3 
// width 进度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值