vue实现抖音时间转盘


Posted in Javascript onSeptember 08, 2019

本文实例为大家分享了vue实现抖音时间转盘的具体代码,供大家参考,具体内容如下

vue实现抖音时间转盘

做了一个抖音时间转盘,还挺简单的,可能我做的很粗糙

用vue做的 才160行代码。

其实很简单 只是大部分人被这个圆给迷惑了

这个圆就是用简单css3就能做 通过rotate来修改计算就能展示出来了。

vue实现抖音时间转盘

然后贴代码。

<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 () { // 生成数据
   // 星期
   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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
style、 currentStyle、 runtimeStyle区别分析
Aug 01 Javascript
javascript一元操作符(递增、递减)使用示例
Aug 07 Javascript
jQuery实现自定义下拉列表
Jan 05 Javascript
javascript中CheckBox全选终极方案
May 20 Javascript
基于JavaScript实现定时跳转到指定页面
Jan 01 Javascript
教你用javascript实现随机标签云效果_附代码
Mar 16 Javascript
详解Node.js模块间共享数据库连接的方法
May 24 Javascript
js改变透明度实现轮播图的算法
Aug 24 Javascript
JavaScript trim 实现去除字符串首尾指定字符的简单方法
Dec 27 Javascript
AjaxUpLoad.js实现文件上传
Mar 05 Javascript
js实现弹窗效果
Aug 09 Javascript
JS原生实现轮播图的几种方法
Mar 23 Javascript
javascript移动端 电子书 翻页效果实现代码
Sep 07 #Javascript
使用 js 简单的实现 bind、call 、aplly代码实例
Sep 07 #Javascript
vue 使用高德地图vue-amap组件过程解析
Sep 07 #Javascript
vue 的 solt 子组件过滤过程解析
Sep 07 #Javascript
javascript的惯性运动实现代码实例
Sep 07 #Javascript
vue的滚动条插件实现代码
Sep 07 #Javascript
微信小程序页面滚动到指定位置代码实例
Sep 07 #Javascript
You might like
PHP制作万年历
2015/01/07 PHP
thinkPHP数据库增删改查操作方法实例详解
2016/12/06 PHP
PHP基于自定义函数生成笛卡尔积的方法示例
2017/09/30 PHP
PHP添加文字水印或图片水印的水印类完整源代码与使用示例
2019/03/18 PHP
面向对象的编程思想在javascript中的运用上部
2009/11/20 Javascript
javascript instanceof 与typeof使用说明
2010/01/11 Javascript
jquery load事件(callback/data)使用方法及注意事项
2013/02/06 Javascript
深入理解JavaScript 闭包究竟是什么
2013/04/12 Javascript
jQuery中empty()方法用法实例
2015/01/16 Javascript
TinyMCE提交AjaxForm获取不到数据的解决方法
2015/03/05 Javascript
基于jQuery实现点击列表加载更多效果
2016/05/31 Javascript
JS+html5制作简单音乐播放器
2020/09/13 Javascript
Vue分页器实现原理详解
2019/06/28 Javascript
微信小程序自定义支持图片的弹窗
2020/12/21 Javascript
原生js实现下拉框选择组件
2021/01/20 Javascript
python自动翻译实现方法
2016/05/28 Python
Python实现ssh批量登录并执行命令
2016/10/25 Python
教你用Python创建微信聊天机器人
2020/03/31 Python
Python操作Sql Server 2008数据库的方法详解
2018/05/17 Python
python破解zip加密文件的方法
2018/05/31 Python
浅析python参数的知识点
2018/12/10 Python
代码总结Python2 和 Python3 字符串的区别
2020/01/28 Python
python ETL工具 pyetl
2020/06/07 Python
python是怎么被发明的
2020/06/15 Python
HTML5之SVG 2D入门3—文本与图像及渲染文本介绍
2013/01/30 HTML / CSS
Sunglasses Shop英国:欧洲领先的太阳镜在线供应商之一
2018/09/19 全球购物
美国领先的宠物用品和宠物食品零售商:Petco
2020/10/28 全球购物
大一自我鉴定范文
2013/12/27 职场文书
网络工程师职业规划
2014/02/10 职场文书
《九色鹿》教学反思
2014/02/27 职场文书
2014年大学庆元旦迎新年活动方案
2014/03/09 职场文书
美术学专业求职信
2014/07/23 职场文书
晋江市委常委班子四风问题整改工作方案
2014/10/26 职场文书
寒假社会实践个人总结
2015/03/06 职场文书
导游词之杭州岳王庙
2019/11/13 职场文书
Python离线安装openpyxl模块的步骤
2021/03/30 Python