vue實(shí)現(xiàn)數(shù)字動(dòng)態(tài)翻牌的效果(開箱即用)
實(shí)現(xiàn)效果圖
原理
將1~9的數(shù)字豎直排版,通過(guò)translate移動(dòng)位置顯示不同數(shù)字,使用transition控制transform屬性有動(dòng)畫效果
技術(shù)點(diǎn)
css 屬性 writing-mode: vertical-lr,使數(shù)字豎直排版
移動(dòng) transform: translate(-50%, -40%); y值控制移動(dòng)至哪個(gè)數(shù)字
transition 控制transform屬性有動(dòng)畫效果
實(shí)現(xiàn)代碼(注釋比較詳細(xì),不再贅述)
<!-- * @Author: mat * @Date: 2019-12-04 14:56:07 * @LastEditTime: 2019-12-04 16:31:52 * @LastEditors: Please set LastEditors * @Description: 實(shí)現(xiàn)數(shù)字翻牌動(dòng)態(tài)效果,css 屬性 writing-mode: vertical-lr,使數(shù)字豎直排版, 2d移動(dòng) transform: translate(-50%, -40%); y值控制移動(dòng)至哪個(gè)數(shù)字,transition 控制transform屬性有動(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 { data() { return { orderNum: ['0', '0', '0', '0', '0', '0', '0', '0'], // 默認(rèn)訂單總數(shù) } }, mounted(){ setTimeout(() => { this.toOrderNum(12654) // 這里輸入數(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 對(duì)數(shù)字字符進(jìn)行滾動(dòng),顯示訂單數(shù)量 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() // 把訂單數(shù)變成字符串 if (num.length < 8) { num = '0' + num // 如未滿八位數(shù),添加"0"補(bǔ)位 this.toOrderNum(num) // 遞歸添加"0"補(bǔ)位 } else if (num.length === 8) { // 訂單數(shù)中加入逗號(hào) // num = num.slice(0, 2) + ',' + num.slice(2, 5) + ',' + num.slice(5, 8) this.orderNum = num.split('') // 將其便變成數(shù)據(jù),渲染至滾動(dòng)數(shù)組 } else { // 訂單總量數(shù)字超過(guò)八位顯示異常 this.$message.warning('總量數(shù)字過(guò)大') } this.setNumberTransform() }, } } </script> <style scoped lang='scss'> /*訂單總量滾動(dòng)數(shù)字設(shè)置*/ .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; /* overflow: hidden; */ } /* 默認(rèn)逗號(hào)設(shè)置 */ .mark-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(/images/text-bg-blue.png) no-repeat center center; background-size: 100% 100%; // background: #ccc; list-style: none; margin-right: 5px; // background:rgba(250,250,250,1); 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>
數(shù)字背景圖片
總結(jié)
以上所述是小編給大家介紹的vue實(shí)現(xiàn)數(shù)字動(dòng)態(tài)翻牌的效果(開箱即用),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
相關(guān)文章
Vue引入高德地圖并觸發(fā)實(shí)現(xiàn)多個(gè)標(biāo)點(diǎn)的示例詳解
這篇文章主要介紹了Vue引入高德地圖并觸發(fā)實(shí)現(xiàn)多個(gè)標(biāo)點(diǎn),主要是在public下的index.html中引入地圖,引入組件設(shè)置寬高100%,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-05-05VUE數(shù)組根據(jù)索引刪除數(shù)據(jù),頁(yè)面同時(shí)更新的實(shí)現(xiàn)方法
這篇文章主要介紹了VUE數(shù)組根據(jù)索引刪除數(shù)據(jù),頁(yè)面同時(shí)更新的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07詳解Vue、element-ui、axios實(shí)現(xiàn)省市區(qū)三級(jí)聯(lián)動(dòng)
這篇文章主要介紹了Vue、element-ui、axios實(shí)現(xiàn)省市區(qū)三級(jí)聯(lián)動(dòng),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05vue3中unplugin-auto-import自動(dòng)引入示例代碼
unplugin-auto-import 這個(gè)插件是為了解決在開發(fā)中的導(dǎo)入問(wèn)題,下面這篇文章主要給大家介紹了關(guān)于vue3中unplugin-auto-import自動(dòng)引入的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02Vue+Java+Base64實(shí)現(xiàn)條碼解析的示例
這篇文章主要介紹了Vue+Java+Base64實(shí)現(xiàn)條碼解析的示例,幫助大家實(shí)現(xiàn)條碼解析,感興趣的朋友可以了解下2020-09-09vue-router實(shí)現(xiàn)tab標(biāo)簽頁(yè)(單頁(yè)面)詳解
這篇文章主要為大家詳細(xì)介紹了vue-router實(shí)現(xiàn)tab標(biāo)簽頁(yè)的相關(guān)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10解決vue 綁定對(duì)象內(nèi)點(diǎn)擊事件失效問(wèn)題
今天小編就為大家分享一篇解決vue 綁定對(duì)象內(nèi)點(diǎn)擊事件失效問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-09-09在vue項(xiàng)目中使用Nprogress.js進(jìn)度條的方法
NProgress.js是輕量級(jí)的進(jìn)度條組件,使用簡(jiǎn)便,可以很方便集成到單頁(yè)面應(yīng)用中。這篇文章主要介紹了在vue項(xiàng)目中使用Nprogress.js進(jìn)度條的方法,需要的朋友可以參考下2018-01-01vue實(shí)現(xiàn)element表格里表頭信息提示功能(推薦)
小編最近接了這樣一個(gè)需求,需要在element表格操作一欄添加提示功能,下面小編給大家?guī)?lái)了基于vue實(shí)現(xiàn)element表格里表頭信息提示功能,需要的朋友參考下吧2019-11-11