大屏組件-數(shù)字滾動(dòng)

_640_1714014493.gif

父組件

<template>
  <div class="app-container rolling-wrap">
    <div style="display: flex">
      <el-button @click="handleChange">變</el-button>
      <el-alert
        type="success"
        :closable="false">
        <template slot="title">
          1悄泥、數(shù)字變化時(shí)會(huì)上下滾動(dòng)數(shù)據(jù)框弛;2莱找、千分號(hào),可改變
        </template>
      </el-alert>
    </div>
    <hr />
    <Index5 :num="num" :symbol="'.'"></Index5>
  </div>
</template>

<script>
import Index5 from './component/index5'
export default {
  components: { Index5 },
  data() {
    return {
      num: 0
    }
  },
  methods: {
    handleChange() {
      const aa = Math.floor((Math.random() * 1000))
      this.num = this.num + aa
      console.log('this.num>>', this.num)
    }
  },
  mounted() {
    setTimeout(() => {
      this.num = 176
    }, 1000)
  }
}
</script>

子組件

<template>
  <div class="rolling-wrap">
    <div class="rolling-item-wrap">
      <div v-for="(item, index) in list" :key="'w-'+index" :class="{ 'glow-animation': isAnimating && item !== symbol, 'rolling-item-w2': item !== symbol}">
        <div v-show="item !== symbol" class="rolling-item width-animation" :style="{transform: `translateY(-${item * 60}px)`}">
          <div class="item">0</div>
          <div class="item">1</div>
          <div class="item">2</div>
          <div class="item">3</div>
          <div class="item">4</div>
          <div class="item">5</div>
          <div class="item">6</div>
          <div class="item">7</div>
          <div class="item">8</div>
          <div class="item">9</div>
        </div>
        <div v-show="item === symbol" class="rolling-item-fh">
          <div class="item-fh">{{ symbol }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Rolling',
  props: {
    // 數(shù)字
    num: {
      type: Number,
      default: 0
    },
    // 符號(hào)
    symbol: {
      type: String,
      default: ','
    }
  },
  data() {
    return {
      list: ['0'],
      isAnimating: true
    }
  },
  watch: {
    num: {
      handler(n) {
        this.isAnimating = false // 標(biāo)記為正在動(dòng)畫中
        const nv = n.toLocaleString().replace(/,/g, this.symbol)
        const length = nv.split('').length
        const aa = JSON.parse(JSON.stringify(this.list))
        for (let i = 0; i < length; i++) {
          if (!aa[i]) {
            aa[i] = '0'
          }
        }
        this.list = aa
        this.$nextTick(() => {
          setTimeout(() => {
            this.isAnimating = true // 動(dòng)畫結(jié)束后重置標(biāo)記
            this.list = nv.split('')
          }, 50)
        })
      },
      immediate: true
    }
  },
  methods: {
    insertPeriodsEveryThreeCharactersFromEnd(inputString) {
      let result = ''
      for (let i = inputString.length - 3; i >= 0; i -= 3) {
        result = '.' + inputString.slice(i, i + 3) + result
      }
      // 處理剩余不足3個(gè)字符的部分(如果存在)
      if (inputString.length % 3 !== 0) {
        result = inputString.slice(0, inputString.length % 3) + result
      }
      return result
    }
  }
}
</script>

<style lang="scss" scoped>
.rolling-wrap {

}
.rolling-item-wrap {
  display: flex;
  overflow: hidden;
}
.rolling-item-w2 {
  border: 1px solid #1587f1;
  border-radius: 3px;
  margin: 10px;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.rolling-item-w2:first-child {
  border: 1px solid #1587f1;
  border-radius: 3px;
  margin: 10px 10px 10px 5px;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.rolling-item-w2:last-child {
  border: 1px solid #1587f1;
  border-radius: 3px;
  margin: 10px 5px 10px 10px;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.rolling-item {
  height: 60px;
  font-weight: bold;
  font-size: 24px;
  color: red;
}

.rolling-item-fh {
  width: 10px;
  height: 60px;
  transition-duration: 1s;
  transition-delay: 0s;
  transition-timing-function: linear;
  font-weight: bold;
  font-size: 24px;
  color: red;
}

.item {
  width: 40px;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.item-fh {
  width: 10px;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 10px 0;
}

.glow-animation {
  animation: glow 1000ms ease-in infinite alternate;
}

@keyframes glow {
  0% {
    border-color: #1587f1;
    box-shadow: 0 0 1px #1587f1, inset 0 0 1px #1587f1, 0 0 1px #1587f1;
  }

  100% {
    border-color: #1587f1;
    box-shadow: 0 0 5px #1587f1, inset 0 0 3px #1587f1, 0 0 3px #1587f1;
  }
}

.width-animation {
  transition-duration: 1s;
  transition-delay: 0s;
  transition-timing-function: linear;
}
</style>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌璧眠,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,427評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異责静,居然都是意外死亡袁滥,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門灾螃,熙熙樓的掌柜王于貴愁眉苦臉地迎上來题翻,“玉大人,你說我怎么就攤上這事腰鬼∏对” “怎么了?”我有些...
    開封第一講書人閱讀 165,747評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵熄赡,是天一觀的道長(zhǎng)姜挺。 經(jīng)常有香客問我,道長(zhǎng)彼硫,這世上最難降的妖魔是什么炊豪? 我笑而不...
    開封第一講書人閱讀 58,939評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮拧篮,結(jié)果婚禮上词渤,老公的妹妹穿的比我還像新娘。我一直安慰自己串绩,他們只是感情好缺虐,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,955評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著礁凡,像睡著了一般高氮。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上把篓,一...
    開封第一講書人閱讀 51,737評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音腰涧,去河邊找鬼韧掩。 笑死,一個(gè)胖子當(dāng)著我的面吹牛窖铡,可吹牛的內(nèi)容都是我干的疗锐。 我是一名探鬼主播,決...
    沈念sama閱讀 40,448評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼费彼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼滑臊!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起箍铲,我...
    開封第一講書人閱讀 39,352評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后昨寞,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,834評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡小染,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,992評(píng)論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了贮折。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片裤翩。...
    茶點(diǎn)故事閱讀 40,133評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖调榄,靈堂內(nèi)的尸體忽然破棺而出踊赠,到底是詐尸還是另有隱情,我是刑警寧澤每庆,帶...
    沈念sama閱讀 35,815評(píng)論 5 346
  • 正文 年R本政府宣布筐带,位于F島的核電站,受9級(jí)特大地震影響扣孟,放射性物質(zhì)發(fā)生泄漏烫堤。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,477評(píng)論 3 331
  • 文/蒙蒙 一凤价、第九天 我趴在偏房一處隱蔽的房頂上張望鸽斟。 院中可真熱鬧,春花似錦利诺、人聲如沸富蓄。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽立倍。三九已至,卻和暖如春侣滩,著一層夾襖步出監(jiān)牢的瞬間口注,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工君珠, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留寝志,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,398評(píng)論 3 373
  • 正文 我出身青樓策添,卻偏偏與公主長(zhǎng)得像材部,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子唯竹,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,077評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容