【组件】翻牌器效果

目录

效果

组件代码

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>

背景素材

相关推荐
FungLeo3 小时前
成为全栈·React 管理后台篇·总复盘:从“接口能调通”到“后台值得使用”
前端·react.js·前端框架·项目复盘·成为全栈
Csvn5 小时前
并发模式:让渲染学会排队、插队和让路
前端
可乐鸡翅yeah_5 小时前
新手梳理:M3U8 线上问题,哪些是前端锅,哪些是后端锅
前端·ios·音视频·实时音视频·m3u8·音视频在线播放
Flynt5 小时前
Linear 用 1000 个 PR 换掉 styled-components,我写了 200 个按钮,把这笔账复现了一遍
前端·css·preact
JavaGuide6 小时前
NVIDIA 又开源了!这次给 AI Agent 加上权限管控
前端·后端
excel6 小时前
prisma 如何处理数据库竞态
前端·数据库·后端
莪_幻尘7 小时前
Skill 体检:30 个 Skill 全凭感觉?体检器先自曝了 8 个“假 0 分
前端·人工智能·llm
风骏时光牛马7 小时前
AI模型综合能力评测:性能、指令遵循与多场景实测对比
前端
Frag0ut8 小时前
Chrome与Chromium内核浏览器在Windows 11上的新特性全景解析
前端·chrome·windows·web安全·chromium·gemini ai·playready drm
hiahiahia1238 小时前
实现完整 Tool Dispatcher
开发语言·前端