web前端实现LED功能、液晶显示时间、数字
2023-12-13 22:06:18
效果演示
html部分
<div id="app">
<!-- 页面 -->
<div class="time-box">
<!-- 时 -->
<div class="house-box">
<bit-component :num="houseTem"></bit-component>
<bit-component :num="houseBit"></bit-component>
</div>
<div class="colon">:</div>
<!-- 分 -->
<div class="minute-box">
<bit-component :num="minuteTem"></bit-component>
<bit-component :num="minuteBit"></bit-component>
</div>
<div class="colon">:</div>
<!-- 秒 -->
<div class="second-box">
<bit-component :num="secondTem"></bit-component>
<bit-component :num="secondBit"></bit-component>
</div>
</div>
</div>
<!-- 组件 -->
<template id="BitComponent">
<div class="clock-box">
<div :class="{transverse: true, 'show-color': [0,2,3,5,6,7,8,9].includes(num)}"></div>
<div class="portrait-box">
<div :class="{portrait: true, 'show-color': [0,4,5,6,8,9].includes(num)}"></div>
<div :class="{portrait: true, 'show-color': [0,1,2,3,4,7,8,9].includes(num)}"></div>
</div>
<div :class="{transverse: true, 'show-color': [2,3,4,5,6,8,9].includes(num)}"></div>
<div class="portrait-box">
<div :class="{portrait: true, 'show-color': [0,2,6,8].includes(num)}"></div>
<div :class="{portrait: true, 'show-color': [0,1,3,4,5,6,7,8,9].includes(num)}"></div>
</div>
<div :class="{transverse: true, 'show-color': [0,2,3,5,6,8,9].includes(num)}"></div>
</div>
</template>
以上代码需要引入以下文件:
1、<link rel="stylesheet" href="./index.css">
2、<script src="/node_modules/vue/dist/vue.js"></script>
3、<script src="./index.js"></script>
JavaScript部分
// 子组件
let BitComponent = {
name: 'BitComponent',
template: '#BitComponent',
props: ['num'],
};
// 页面
new Vue({
el: "#app",
components: { BitComponent },
data() {
return {}
},
created() {
setInterval(() => {
let dateTime = new Date(),
// yer = dateTime.getFullYear(),
// moth = String(dateTime.getMonth() + 1),
// day = dateTime.getDate().toString(),
house = dateTime.getHours().toString(),
minute = dateTime.getMinutes().toString(),
second = dateTime.getSeconds().toString();
// 补〇
// moth = ('00' + moth).slice(moth.length);
// day = ('00' + day).slice(day.length);
house = ('00' + house).slice(house.length);
minute = ('00' + minute).slice(minute.length);
second = ('00' + second).slice(second.length);
this.houseTem = Number(house[0]);
this.houseBit = Number(house[1]);
this.minuteTem = Number(minute[0]);
this.minuteBit = Number(minute[1]);
this.secondTem = Number(second[0]);
this.secondBit = Number(second[1]);
}, 1000);
},
});
css部分
/* ---------------------页面样式--------------------- */
body {
background-color: #333;
}
.colon {
font-size: 68px;
font-weight: 700;
color: #FF0000;
margin-top: -20px;
}
.time-box {
width: 460px;
display: flex;
justify-content: space-between;
align-items: center;
}
/* 时分秒 */
.house-box,
.minute-box,
.second-box {
width: 130px;
display: flex;
justify-content: space-between;
align-items: center;
}
/* ---------------------页面样式--------------------- */
/* ---------------------组件样式--------------------- */
.clock-box {
width: 60px;
}
/* 横向显示 */
.transverse {
width: 40px;
height: 10px;
margin-left: 10px;
background-color: #444;
}
/* 纵向容器 */
.portrait-box {
display: flex;
justify-content: space-between;
align-items: center;
}
/* 纵向显示 */
.portrait {
width: 10px;
height: 30px;
background-color: #444;
}
.show-color {
background-color: #FF0000;
}
/* ---------------------组件样式--------------------- */
文章来源:https://blog.csdn.net/weixin_51157081/article/details/120249472
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!