vue實(shí)現(xiàn)翻牌動(dòng)畫
本文實(shí)例為大家分享了vue實(shí)現(xiàn)翻牌動(dòng)畫的具體代碼,供大家參考,具體內(nèi)容如下
應(yīng)用場(chǎng)景
常用于大屏訂單數(shù)量展示
原理
- 利用css writing-mode: vertical-rl 使數(shù)字垂直排列
- 利用css transform 使數(shù)字滾動(dòng)
實(shí)現(xiàn)思路
- 根據(jù)css先讓數(shù)字垂直排列,總共設(shè)置8列
- 根據(jù)組件傳遞的數(shù)值,如果不滿8位,遞歸補(bǔ)零
- 補(bǔ)零之后,循環(huán)根據(jù) translate(-50%, -${numberArr[index] * 10}%,查看動(dòng)畫
<template> ? ? <div class="chartNum"> ? ? ? ? <div class="box-item"> ? ? ? ? ? ? <li ? ? ? ? ? ? ? ? :class="{'number-item':!isNaN(item),'mark-item':!isNaN(item)}" ? ? ? ? ? ? ? ? v-for="(item,index) in orderNum" ? ? ? ? ? ? ? ? :key="index"> ? ? ? ? ? ? ? ? <span v-if="!isNaN(item)"> ? ? ? ? ? ? ? ? ? ? <i ref="numberItem">0123456789</i> ? ? ? ? ? ? ? ? </span> ? ? ? ? ? ? ? ? <span class="comma" v-else>{{item}}</span> ? ? ? ? ? ? </li> ? ? ? ? </div> ? ? </div> </template> <script> ? ? export default { ? ? ? ? name: "hChartNum", ? ? ? ? props:{ ? ? ? ? ? num:{ ? ? ? ? ? ? ? type:Number, ? ? ? ? ? ? ? default:1123 ? ? ? ? ? } ? ? ? ? }, ? ? ? ? data() { ? ? ? ? ? ? return { ? ? ? ? ? ? ? ? orderNum: ['0', '0', '0', '0', '0', '0', '0', '0'], // 默認(rèn)訂單總數(shù) ? ? ? ? ? ? } ? ? ? ? }, ? ? ? ? mounted(){ ? ? ? ? ? ? setTimeout(() => { ? ? ? ? ? ? ? ? this.toOrderNum(this.num) // 這里輸入數(shù)字即可調(diào)用 ? ? ? ? ? ? }, 500); ? ? ? ? }, ? ? ? ? methods:{ ? ? ? ? ? ? // 設(shè)置文字滾動(dòng) ? ? ? ? ? ? setNumberTransform(){ ? ? ? ? ? ? ? ? const numberItems = this.$refs.numberItem // 拿到數(shù)字的ref,計(jì)算元素?cái)?shù)量 ? ? ? ? ? ? ? ? const numberArr = this.orderNum.filter(item => !isNaN(item)) ? ? ? ? ? ? ? ? // 結(jié)合css,讓文字滾動(dòng)起來 ? ? ? ? ? ? ? ? for (let index = 0; index < numberItems.length; index++) { ? ? ? ? ? ? ? ? ? ? const elem = numberItems[index]; ? ? ? ? ? ? ? ? ? ? elem.style.transform = `translate(-50%, -${numberArr[index] * 10}%)` ? ? ? ? ? ? ? ? } ? ? ? ? ? ? }, ? ? ? ? ? ? // 處理訂單數(shù)字 ? ? ? ? ? ? toOrderNum(num){ ? ? ? ? ? ? ? ? num = num.toString(); ? ? ? ? ? ? ? ? if(num.length < 8){ ? ? ? ? ? ? ? ? ? ? num = '0' + num; // 未滿8位,補(bǔ)零 ? ? ? ? ? ? ? ? ? ? this.toOrderNum(num); // 遞歸添加"0"補(bǔ)位 ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? else if(num.length == 8){ ? ? ? ? ? ? ? ? ? ? this.orderNum = num.split('') ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? else{ ? ? ? ? ? ? ? ? ? ? // 數(shù)據(jù)量超過8位 ? ? ? ? ? ? ? ? ? ? this.$message.error('數(shù)據(jù)量過大'); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? this.setNumberTransform(); ? ? ? ? ? ? } ? ? ? ? } ? ? } </script> <style scoped lang="less"> ? ? .box-item{ ? ? ? ? position: relative; ? ? ? ? height: 100px; ? ? ? ? font-size: 54px; ? ? ? ? line-height: 41px; ? ? ? ? text-align: center; ? ? ? ? list-style: none; ? ? ? ? color: #2D7CFF; ? ? ? ? writing-mode: vertical-lr; ? ? ? ? text-orientation: upright; ? ? ? ? -moz-user-select: none; ? ? ? ? -webkit-user-select: none; /*webkit瀏覽器*/ ? ? ? ? -ms-user-select: none; /*IE10*/ ? ? ? ? -khtml-user-select: none; /*早期瀏覽器*/ ? ? ? ? user-select: none; ? ? } ? ? /*默認(rèn)逗號(hào)設(shè)置*/ ? ? .number-item{ ? ? ? ? width: 10px; ? ? ? ? height: 100px; ? ? ? ? margin-right: 5px; ? ? ? ? line-height: 10px; ? ? ? ? font-size: 48px; ? ? ? ? position: relative; ? ? ? ? & > span{ ? ? ? ? ? ? position: absolute; ? ? ? ? ? ? width: 100%; ? ? ? ? ? ? bottom: 0; ? ? ? ? ? ? writing-mode: vertical-rl; ? ? ? ? ? ? text-orientation: upright; ? ? ? ? ? } ? ? } ? ? /*滾動(dòng)數(shù)字設(shè)置*/ ? ? .number-item { ? ? ? ? width: 41px; ? ? ? ? height: 75px; ? ? ? ? background: url(./img/bg.jpg) no-repeat center center; ? ? ? ? background-size: 100% 100%; ? ? ? ? list-style: none; ? ? ? ? margin-right: 5px; ? ? ? ? border-radius:4px; ? ? ? ? border:1px solid rgba(221,221,221,1); ? ? ? ? & > span{ ? ? ? ? ? ? position: relative; ? ? ? ? ? ? display: inline-block; ? ? ? ? ? ? margin-right: 10px; ? ? ? ? ? ? width: 100%; ? ? ? ? ? ? height: 100%; ? ? ? ? ? ? writing-mode: vertical-rl; ? ? ? ? ? ? text-orientation: upright; ? ? ? ? ? ? overflow: hidden; ? ? ? ? ? ? & > i { ? ? ? ? ? ? ? ? font-style: normal; ? ? ? ? ? ? ? ? position: absolute; ? ? ? ? ? ? ? ? top:11px; ? ? ? ? ? ? ? ? left: 50%; ? ? ? ? ? ? ? ? transform: translate(-50%,0); ? ? ? ? ? ? ? ? transition: transform 1s ease-in-out; ? ? ? ? ? ? ? ? letter-spacing: 10px; ? ? ? ? ? ? } ? ? ? ? } ? ? } ? ? .number-item:last-child { ? ? ? ? margin-right: 0; ? ? } </style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue .then和鏈?zhǔn)秸{(diào)用操作方法
這篇文章主要介紹了vue .then和鏈?zhǔn)秸{(diào)用操作方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07vue百度地圖通過地址名稱獲取地址的經(jīng)緯度gps問題(具體步驟)
在Vue項(xiàng)目中,可以通過使用百度地圖JavaScript?API來實(shí)現(xiàn)根據(jù)地址名稱獲取經(jīng)緯度GPS的功能,本文分步驟給大家詳細(xì)講解vue百度地圖獲取經(jīng)緯度的實(shí)例,感興趣的朋友一起看看吧2023-05-05vue實(shí)現(xiàn)移動(dòng)端table表格簡(jiǎn)單方法
這篇文章主要給大家介紹了關(guān)于vue實(shí)現(xiàn)移動(dòng)端table表格簡(jiǎn)單方法的相關(guān)資料,使用Vue.js開發(fā)移動(dòng)應(yīng)用程序時(shí),經(jīng)常需要使用各種UI組件,其中el-table是一個(gè)常用的表格組件,可以方便地展示數(shù)據(jù),需要的朋友可以參考下2023-09-09vue + elementUI實(shí)現(xiàn)省市縣三級(jí)聯(lián)動(dòng)的方法示例
這篇文章主要介紹了vue + elementUI實(shí)現(xiàn)省市縣三級(jí)聯(lián)動(dòng)的方法示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10vue移動(dòng)端實(shí)現(xiàn)手指滑動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了vue移動(dòng)端實(shí)現(xiàn)手指滑動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06webpack安裝配置與常見使用過程詳解(結(jié)合vue)
這篇文章主要介紹了webpack安裝配置與常見使用過程,主要結(jié)合vue實(shí)現(xiàn),通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06element?ui?el-calendar日歷組件使用方法總結(jié)
這篇文章主要給大家介紹了關(guān)于element?ui?el-calendar日歷組件使用方法的相關(guān)資料,elementui是一款基于Vue.js的UI框架,其中的日歷組件calendar是elementui中非常常用的組件之一,需要的朋友可以參考下2023-07-07Vue中的異步組件函數(shù)實(shí)現(xiàn)代碼
這篇文章主要介紹了Vue中的異步組件函數(shù)實(shí)現(xiàn)代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-07-07vue的style綁定background-image的方式和其他變量數(shù)據(jù)的區(qū)別詳解
今天小編就為大家分享一篇vue的style綁定background-image的方式和其他變量數(shù)據(jù)的區(qū)別詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-09-09