【组件】翻牌器效果

目录

效果

组件代码

html 复制代码
<template>
  <div
    class="card-flop"
    :style="{
      height: typeof height === 'number' ? `${height}px` : height,
      '--box-width': typeof boxWidth === 'number' ? `${boxWidth}px` : boxWidth,
      '--box-height': typeof boxHeight === 'number' ? `${boxHeight}px` : boxHeight,
      '--color': color
    }"
  >
    <div
      :class="{ 'card-flop__number': true, 'is-comma': isNotNumber(number) }"
      v-for="(number, index) in countArray"
      :key="`num-${index}`"
    >
      <div v-if="isNotNumber(number)" class="card-flop__number-comma">
        <span>{{ number }}</span>
      </div>
      <div v-else class="card-flop__number-box" :style="{ transform: getTransform(number, index) }">
        <div v-for="(item, index) in numbers" class="card-flop__number-item" :key="`item-${index}`">
          <span>{{ item }}</span>
        </div>
      </div>
    </div>
    <div class="card-flop__unit">
      <span>{{ unit }}</span>
    </div>
  </div>
</template>

<script >
export default {
  name: 'CardFlopCom',
  components: {},
  props: {
    count: {
      type: [String, Number],
      default: 0
    },
    height: {
      type: Number,
      default: 32
    },
    boxWidth: {
      type: Number,
      default: 24
    },
    boxHeight: {
      type: Number,
      default: 32
    },
    unit: {
      type: String,
      default: '条'
    },
    color: {
      type: String,
      default: '#fff'
    }
  },

  data() {
    return {
      numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    }
  },

  computed: {
    countArray() {
      // 将数字转换为带千位分隔符的字符串
      const formattedNumber = Number(this.count).toLocaleString()
      // 分割成数组,包括逗号
      return formattedNumber.split('')
    }
  },
  methods: {
    isNotNumber(number) {
      return [',', '.'].includes(number)
    },
    getTransform(number) {
      const offset = Number(number) * this.boxHeight
      return `translateY(-${offset}px)`
    }
  }
}
</script>

<style lang="scss" scoped>
.card-flop {
  display: flex;
  align-items: baseline;
  justify-content: center;

  &__number {
    height: var(--box-height);
    color: var(--color);

    background-size: 100% 100%;
    background-repeat: no-repeat;
    margin-right: 3px;
    overflow: hidden;

    &:not(.is-comma) {
      width: var(--box-width);
      // background-image: url('@/assets/images/screen-zhidu/card_flop_bg.png');
      background-image: url('~@/assets/images/screen-zhidu/card_flop_bg.png');
    }

    &.is-comma {
      margin-right: 2px;
    }

    &-box {
      transition: transform 1s ease-in-out;
    }

    &-item {
      width: var(--box-width);
      height: var(--box-height);

      display: flex;
      align-items: center;
      justify-content: center;
      span {
        font-weight: bold;
        font-size: 26px;
      }
    }
  }

  &__unit {
    font-size: 16px;
    color: rgba(225, 239, 255, 0.6);
    margin-left: 2px;
  }
}
</style>

背景素材

相关推荐
sunbyte31 分钟前
50天50个小项目 (Vue3 + Tailwindcss V4) ✨ | Split Landing Page(拆分展示页)
前端·javascript·css·vue·tailwindcss
疯狂的沙粒1 小时前
React与Vue的内置指令对比
开发语言·前端·javascript·vue.js
菥菥爱嘻嘻1 小时前
React---day4
前端·react.js·前端框架
会飞的土拨鼠呀1 小时前
dis css port brief 命令详细解释
前端·css·网络
米粉03051 小时前
Ajax(Asynchronous JavaScript and XML)
xml·javascript·ajax
EndingCoder1 小时前
React从基础入门到高级实战:React 核心技术 - React 状态管理:Context 与 Redux
前端·javascript·react.js·前端框架
码界奇点1 小时前
React 生命周期与 Hook:从原理到实战全解析
前端·react.js·前端框架·生活·reactjs·photoshop
GISer_Jing1 小时前
[低代码表单生成器设计基础]ElementUI中Layout布局属性&Form表单属性详解
前端·低代码·elementui
GISer_Jing1 小时前
低代码——表单生成器Form Generator详解(二)——从JSON配置项到动态渲染表单渲染
前端·vue.js
万米商云1 小时前
商城前端监控体系搭建:基于 Sentry + Lighthouse + ELK 的全链路监控实践
前端·elk·sentry