vue實現(xiàn)抖音時間轉盤
更新時間:2019年09月08日 09:11:50 作者:沙鑫741
這篇文章主要為大家詳細介紹了vue實現(xiàn)抖音時間轉盤,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue實現(xiàn)抖音時間轉盤的具體代碼,供大家參考,具體內(nèi)容如下

做了一個抖音時間轉盤,還挺簡單的,可能我做的很粗糙
用vue做的 才160行代碼。
其實很簡單 只是大部分人被這個圓給迷惑了
這個圓就是用簡單css3就能做 通過rotate來修改計算就能展示出來了。

然后貼代碼。
<template>
<div class="main">
<div class="timeBox">
<div class="yearBox box">{{year}}</div>
<div class="dayBox box" :style="'transform: rotate('+(360/day.length)*curDay+'deg)'">
<ul class="container">
<li
v-for="(v,i) in day"
:key="i"
:style="'transform: rotate('+(-360/day.length) * (i+1) +'deg);transform-origin: -100% 50% 0px;margin-left:150px;margin-top:90px'"
>{{v}}</li>
</ul>
</div>
<div class="hourBox box" :style="'transform: rotate('+(-360/hour.length)*curHour+'deg)'">
<ul class="container">
<li
v-for="(v,i) in hour"
:key="i"
:style="'transform: rotate('+(360/hour.length)*i+'deg);transform-origin: -200% 50% 0px;margin-left:300px;margin-top:190px'"
>{{v}}</li>
</ul>
</div>
<div class="minutesBox box" :style="'transform: rotate('+(-360/minutes.length)*curMin+'deg)'">
<ul class="container">
<li
v-for="(v,i) in minutes"
:key="i"
:style="'transform: rotate('+(360/minutes.length)*i+'deg);transform-origin: -300% 50% 0px;margin-left:450px;margin-top:290px'"
>{{v}}</li>
</ul>
</div>
<div class="secondBox" :style="'transform: rotate('+(-360/seconds.length)*curSec+'deg)'">
<ul class="container">
<li
v-for="(v,i) in seconds"
:key="i"
:style="'transform: rotate('+(360/seconds.length)*i+'deg);transform-origin: -400% 50% 0px;margin-left:600px;margin-top:390px'"
>{{v}}</li>
</ul>
</div>
</div>
</div>
</template>
<script>
export default {
data: function () {
return {
data: ['零', '壹', '貳', '叁', '肆', '伍', '陸', '柒', '捌', '玖', '拾', '佰', '仟', '萬'],
hour: [],
curHour: 0,
day: [],
curDay: 0,
minutes: [],
curMin: 0,
seconds: [],
curSec: 0,
year: ''
}
},
created () {
this.dealData()
this.seconds = JSON.parse(JSON.stringify(this.minutes))
var sky = ['', '辛', '壬', '癸', '甲', '乙', '丙', '丁', '戊', '己', '庚']
var land = ['', '酉', '戌', '亥', '子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申']
var one = new Date().getFullYear() % 10
var two = new Date().getFullYear() % 12
this.year = sky[one] + land[two]
setInterval(() => {
this.getTime()
}, 1000)
},
methods: {
dealData () { // 生成數(shù)據(jù)
// 星期
for (let i = 0; i < 7; i++) {
this.day.push('星期' + this.data[i + 1])
}
// 小時
for (let i = 0; i < 24; i++) {
if (i < 11) {
this.hour.push(this.data[i])
} else {
this.hour.push((parseInt(i / 10) > 1 ? this.data[parseInt(i / 10)] : '') + '拾' + (parseInt(i % 10) !== 0 ? this.data[i % 10] : ''))
}
}
// 分鐘
for (let i = 0; i < 60; i++) {
if (i < 11) {
this.minutes.push(this.data[i])
} else {
this.minutes.push((parseInt(i / 10) > 1 ? this.data[parseInt(i / 10)] : '') + '拾' + (parseInt(i % 10) !== 0 ? this.data[i % 10] : ''))
}
}
},
getTime () { // 獲取時間
var now = new Date()
this.curSec = now.getSeconds()
this.curDay = now.getDay()
this.curMin = now.getMinutes()
this.curHour = now.getHours()
}
}
}
</script>
<style lang="scss" scoped>
.box{
position: absolute;
transition: 1s;
}
.main{
width: 100%;
height: 100vh;
overflow: hidden;
background: #ccc;
}
.yearBox{
top: 50%;
left: 50%;
height: 40px;
width: 40px;
margin-top: -20px;
margin-left: -20px;
line-height: 40px;
text-align: center;
font-size: 18px;
}
.timeBox{
width: 800px;
height: 800px;
margin: 0 auto;
position: relative;
}
.dayBox {
width: 200px;
height: 200px;
top: 300px;
left: 300px;
}
.hourBox {
width: 400px;
height: 400px;
top: 200px;
left: 200px;
}
.minutesBox {
width: 600px;
height: 600px;
top: 100px;
left: 100px;
}
.secondBox {
width: 800px;
height: 800px;
top: 0;
left: 0;
position: absolute;
}
.container {
overflow:auto;
li {
width: 50px;
height: 20px;
font-size: 12px;
position: absolute;
}
}
</style>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關文章
Vue子級如何向父級傳遞數(shù)據(jù)(自定義事件)
這篇文章主要介紹了Vue子級如何向父級傳遞數(shù)據(jù)(自定義事件),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-08-08
vue-router重寫push方法,解決相同路徑跳轉報錯問題
這篇文章主要介紹了vue-router重寫push方法,解決相同路徑跳轉報錯問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08
el-select如何獲取當前選中的對象所有(item)數(shù)據(jù)
在開發(fā)業(yè)務場景中我們通常遇到一些奇怪的需求,下面這篇文章主要給大家介紹了關于el-select如何獲取當前選中的對象所有(item)數(shù)據(jù)的相關資料,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2023-11-11
vue根據(jù)權限動態(tài)渲染按鈕、組件等的函數(shù)式組件實現(xiàn)
這篇文章主要介紹了vue根據(jù)權限動態(tài)渲染按鈕、組件等的函數(shù)式組件實現(xiàn)方式,具有很好的參考價值,希望杜大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11
前端開發(fā)指南之vue-grid-layout的使用實例
vue-grid-layout是一個vue柵格拖動布局的組件,下面這篇文章主要給大家介紹了關于前端開發(fā)指南之vue-grid-layout使用的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-09-09

