Vue编写炫酷的时钟插件
作者:lucky.麒麟 发布时间:2023-07-02 16:32:27
标签:Vue,时钟插件
本文实例为大家分享了Vue编写时钟插件的具体代码,供大家参考,具体内容如下
效果图
代码奉上:
<template>
<div class="clock">
<div class="flip">
<div class="digital front" :data-number="nextTimes[0]"></div>
<div class="digital back" :data-number="nowTimes[0]"></div>
</div>
<div class="flip">
<div class="digital front" :data-number="nextTimes[1]"></div>
<div class="digital back" :data-number="nowTimes[1]"></div>
</div>
<em class="divider">:</em>
<div class="flip">
<div class="digital front" :data-number="nextTimes[2]"></div>
<div class="digital back" :data-number="nowTimes[2]"></div>
</div>
<div class="flip">
<div class="digital front" :data-number="nextTimes[3]"></div>
<div class="digital back" :data-number="nowTimes[3]"></div>
</div>
<em class="divider">:</em>
<div class="flip">
<div class="digital front" :data-number="nextTimes[4]"></div>
<div class="digital back" :data-number="nowTimes[4]"></div>
</div>
<div class="flip">
<div class="digital front" :data-number="nextTimes[5]"></div>
<div class="digital back" :data-number="nowTimes[5]"></div>
</div>
</div>
</template>
<script>
export default {
name: "ClockData",
data () {
return {
duration: 650,
nowTimes: [],
nextTimes: [],
timer: {},
}
},
mounted() {
this.initDate();
this.timer = setInterval(() => {
this.updateTime();
}, 1000)
},
methods: {
initDate() {
let now = new Date();
this.nowTimes = this.getTimeFromDate(new Date(now.getTime() - 1000));
this.nextTimes = this.getTimeFromDate(now);
},
updateTime() {
let now = new Date();
let nowTimes = this.getTimeFromDate(new Date(now.getTime() - 1000));
let nextTimes = this.getTimeFromDate(now);;
for (let i = 0; i < 6; i++) {
if (nowTimes[i] !== nextTimes[i]) {
this.setSpin(i, nowTimes[i], nextTimes[i]);
}
}
},
setSpin(index, nowTime, nextTime) {
let nodes = document.querySelectorAll(".flip");
nodes[index].classList.add('running');
this.nowTimes.splice(index, 1, nowTime);
this.nextTimes.splice(index, 1, nextTime);
setTimeout(() => {
nodes[index].classList.remove('running');
this.nowTimes.splice(index, 1, nextTime);
}, this.duration)
},
getTimeFromDate(date) {
let numTime = [];
let timeStr = date
.toTimeString()
.slice(0, 8)
.split(":")
.join("");
for (let i = 0; i < timeStr.length; i++) {
numTime.push(parseInt(timeStr[i]));
}
return numTime;
}
},
destroyed() {
// 销毁定时器
clearInterval(this.timer);
}
}
</script>
<style scoped>
.clock {
display: flex;
}
.clock .divider {
font-size: 66px;
line-height: 102px;
font-style: normal;
}
.clock .flip {
position: relative;
width: 60px;
height: 100px;
margin: 2px;
font-size: 66px;
line-height: 100px;
text-align: center;
background: white;
border: 1px solid black;
border-radius: 12px;
}
.clock .flip .digital::before, .clock .flip .digital::after {
position: absolute;
content: attr(data-number);
left: 0;
right: 0;
color: white;
background: black;
overflow: hidden;
-webkit-perspective: 160px;
perspective: 160px;
}
.clock .flip .digital::before {
top: 0;
bottom: 50%;
border-bottom: 1px solid #666;
border-radius: 10px 10px 0 0;
}
.clock .flip .digital::after {
top: 50%;
bottom: 0;
line-height: 0;
border-radius: 0 0 10px 10px;
}
.clock .flip .back::before,
.clock .flip .front::after {
z-index: 1;
}
.clock .flip .back::after {
z-index: 2;
}
.clock .flip .front::before {
z-index: 3;
}
.clock .flip .back::after {
-webkit-transform-origin: center top;
transform-origin: center top;
-webkit-transform: rotateX(0.5turn);
transform: rotateX(0.5turn);
}
.clock .flip.running .front::before {
-webkit-transform-origin: center bottom;
transform-origin: center bottom;
-webkit-animation: frontFlipDown 0.6s ease-in-out;
animation: frontFlipDown 0.6s ease-in-out;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.clock .flip.running .back::after {
-webkit-animation: backFlipDown 0.6s ease-in-out;
animation: backFlipDown 0.6s ease-in-out;
}
@-webkit-keyframes frontFlipDown {
to {
-webkit-transform: rotateX(0.5turn);
transform: rotateX(0.5turn);
}
}
@keyframes frontFlipDown {
to {
-webkit-transform: rotateX(0.5turn);
transform: rotateX(0.5turn);
}
}
@-webkit-keyframes backFlipDown {
to {
-webkit-transform: rotateX(0);
transform: rotateX(0);
}
}
@keyframes backFlipDown {
to {
-webkit-transform: rotateX(0);
transform: rotateX(0);
}
}
</style>
来源:https://blog.csdn.net/yhflyl/article/details/107488909


猜你喜欢
- Python 中的 timeit 模块可以用来测试一段代码的执行耗时,如一个变量赋值语句的执行时间,一个函数的运行时间等。timeit 模块
- 早听说用python做网络爬虫非常方便,正好这几天单位也有这样的需求,需要登陆XX网站下载部分文档,于是自己亲身试验了一番,效果还不错。本例
- 在我前一阵子刚刚写了“HTML5与Flash,不得不说的话题”的评论后,如各位所料,由于牵扯到多方利益和未来标准制定的角色份量,这不,有可能
- 本文实例讲述了Python实现的简单计算器功能。分享给大家供大家参考,具体如下:使用python编写一款简易的计算器计算器效果图首先搭建计算
- import reimport urllib2import cookielibdef renren():
- 01、介绍在编程语言中,字符串是一种重要的数据结构。在 Golang 语言中,因为字符串只能被访问,不能被修改,所以,如果我们在 Golan
- 搜索是大数据领域里常见的需求。Splunk和ELK分别是该领域在非开源和开源领域里的领导者。本文利用很少的Python代码实现了一个基本的数
- 一直以来,每次调用Ajax方法都需要创建一次 Microsoft.XMLHTTP 对象,今天在使用Ajax技术做一个类似聊天室的
- 1 回表的性能消耗无论单列索引 还是 联合索引,一个索引就对应一个独立的B+索引树,索引树节点仅包含:索引里的字段值主键值即使根据索引树按条
- Python开发环境配置好了,但发现自带的代码编辑器貌似用着有点不大习惯啊,所以咱们就找一个“好用的”代码编辑器吧,网上搜了一下资料,Pyt
- queue模块简介queue模块是Python内置的标准模块,模块实现了三种类型的队列,它们的区别仅仅是条目取回的顺序,分别由3个类进行表示
- 一、系统资源使用限制的必要性探讨对于一个脚本,最基础的限制是要限制单进程实例以保证了不会存在多个进程实例、在运行程序主体逻辑前检测系统资源剩
- Pygame是一个超好用的SDL绑定。自从有了Pygame,妈妈再也不用担心我内存泄漏了。但是这里有一个问题,Pygame的Movie模块已
- 一、前言了解过flask的python开发者想必都知道flask中核心机制莫过于上下文管理,当然学习flask如果不了解其中的处理流程,可能
- 下面我们用HTML来上传3个文件看看,它包含了文本描述字段和多项选择:upload.htm<HTML> <BOD
- 设计与开发之间本有一线界限,但当时代步入又一个十年,这个线变得更加模糊甚至感觉不到它的存在。使用PS设计网页版面,足矣?或许五年前是吧!现在
- 一 MySQL的内部组件结构大体来说,MySQL 可以分为 Server 层和存储引擎层两部分。1.1 service层主要包括连接器、查询
- PyTorch创建自己的数据集图片文件在同一的文件夹下思路是继承 torch.utils.data.Dataset,并重点重写其 __get
- 在使用Keras搭建验证码识别模型时,需要大量的验证码图片。在这里,使用captcha模块生成验证码图片,验证码图片名称为验证码上显示的字符
- 背景为了更好的发展自身的测试技能,应对测试行业以及互联网行业的迭代变化。自学python以及自动化测试。虽然在2017年已经开始接触了sel