首页 > 其他分享 >制作一个简易闹钟

制作一个简易闹钟

时间:2023-06-30 17:00:53浏览次数:23  
标签:width 制作 transform height 简易 闹钟 position border transparent

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.clock {
width: 400px;
height: 400px;
background-color: #000;
border: 30px solid #808080;
border-radius: 50%;

position: relative;
}

.point {
width: 10px;
height: 10px;
background-color: #fff;

position: absolute;
/* calc 计算函数 可以计算尺寸单位的大小 运算符的两端需要添加空格 */
left: calc(50% - 5px);
top: 10px;

border-radius: 5px;

transform-origin: center 190px;

transform: rotate(0deg);
}

.point-container {
width: 400px;
height: 400px;
position: absolute;
top: 0;
left: 0;
}

.hour {
width: 30px;
height: 100px;
background-color: #575757;

position: absolute;
left: calc(50% - 15px);
top: 100px;

transform-origin: center bottom;
transform: rotate(0deg);

transition: all 0.5s linear;
}

.hour::before {
content: '';
display: block;
width: 0;
height: 0;
border-style: solid;
border-width: 15px;
border-color: transparent transparent #575757 transparent;

position: absolute;
top: -30px;
}

.minute {
width: 20px;
height: 150px;
background-color: #fff;

position: absolute;
left: calc(50% - 10px);
top: 50px;

transform-origin: center bottom;
transform: rotate(0deg);

transition: all 0.5s linear;
}

.minute::before {
content: '';
display: block;
width: 0;
height: 0;
border-style: solid;
border-width: 10px;
border-color: transparent transparent #fff transparent;

position: absolute;
top: -20px;
}

.second {
width: 10px;
height: 180px;
background-color: #f00;

position: absolute;
left: calc(50% - 5px);
top: 20px;

transform-origin: center bottom;
transform: rotate(0deg);

transition: all 0.5s linear;
}

.second::before {
content: '';
display: block;
width: 0;
height: 0;
border-style: solid;
border-width: 5px;
border-color: transparent transparent #f00 transparent;

position: absolute;
top: -10px;
}

.cover {
width: 50px;
height: 50px;
background-color: #f00;
border-radius: 50%;

position: absolute;
left: calc(50% - 25px);
top: calc(50% - 25px);
}
</style>
</head>

<body>
<div class="clock">
<!-- html 模板 -->
<!-- <div class="point"></div> -->
<div class="point-container"></div>

<div class="hour"></div>
<div class="minute"></div>
<div class="second"></div>
<div class="cover"></div>
</div>
</body>

<script>
const pointContainer = document.querySelector('.point-container')
const hourEl = document.querySelector('.hour')
const minuteEl = document.querySelector('.minute')
const secondEl = document.querySelector('.second')


// 渲染时钟的表盘
function renderClock() {
// 页面内容的中间变量
let html = ''

// 渲染刻度
for (let i = 0; i < 60; i++) {
// 计算高度
let height = i % 5 === 0 ? 'height: 20px' : ''

html += `<div class="point" style="transform: rotate(${i * 6}deg); ${height}"></div>`
}

pointContainer.innerHTML = html
}

// 渲染指针
function renderPointer() {
// 设置指针的旋转角度
hourEl.style.transform = `rotate(${hRound * 360 + hour * 30}deg)`
minuteEl.style.transform = `rotate(${mRound * 360 + minute * 6}deg)`
secondEl.style.transform = `rotate(${sRound * 360 + second * 6}deg)`
}

renderClock();


// 声明时钟的变量
let hour = 11
let minute = 59
let second = 45

// 指针旋转的圈数
let hRound = 0
let mRound = 0
let sRound = 0

// 初始化指针
renderPointer()

// 渲染循环
setInterval(() => {
// 先执行指针旋转逻辑

second++
// 进行进位判断
if (second >= 60) {
minute++
sRound++
second = 0
if (minute >= 60) {
hour++
mRound++
minute = 0
if (hour >= 12) {
hour = 0
hRound++
}
}
}

// 设置指针的旋转角度
renderPointer()
}, 1000)


// 总结
// 1. 创建刻度的html模板
// 2. 寻找旋转中心并进行验证
// 3. 通过 js 代码循环渲染刻度
</script>

</html>

标签:width,制作,transform,height,简易,闹钟,position,border,transparent
From: https://www.cnblogs.com/ckyjbd/p/17517264.html

相关文章

  • Mac音乐制作软件-Logic Pro
    LogicPro是苹果公司开发的专业音乐制作软件,为音乐制作人、作曲家和音频工程师提供全面而强大的工具和功能。→→↓↓载LogicPro 多轨录音和编辑:LogicPro支持无限多轨录音和编辑,可以同时处理多个音频和MIDI轨道。用户可以轻松地录制、编辑和排列各种乐器和声音。内置......
  • 贪吃蛇游戏制作(附源码)
    CSS:部分*{margin:0;padding:0;}.wrap{width:600px;margin:0auto;position:relative;}p{position:absolute;left:73%;top:10%;}h1{text-align:center;margin-bottom:20px;}#score{text-a......
  • 贪吃蛇制作js
    <!DOCTYPEhtml><html><head><title>贪吃蛇游戏</title><style>#game-board{width:400px;height:400px;border:1pxsolid#000;position:relative;}.snake{width:20px;height:20......
  • 我制作的一个简单的跳棋小游戏
    我用虚幻5制作的简单的3D跳棋小游戏,可以本地多人对战以及和AI对战,已经上传到了itch.io。目前跳棋功能已经完善,其他棋类游戏留待以后加入。支持中英文。支持两种棋盘,支持经典玻璃弹珠和其他不透明弹珠。游戏网页链接......
  • 使用Rufus制作PROXMOX VE 安装优盘的步骤
    Rufus是一个可以帮助格式化和创建可引导USB闪存盘的工具,比如USB随身碟,记忆棒等等。Rufus具有体积小,速度快,功能全面等优势,是非常理想的安装盘制作工具。Rufus当前版本为3.13,下载地址为https://rufus.ie/,推荐使用便携版。ProxmoxVE是一款套开源的虚拟化管理软件,用户可通过网页的......
  • 便携版jdk制作
    便携版即相当于绿色版,制作好后复制到对应位数的任意Windows环境下即可使用,无需继续执行标准的安装过程。以下制作过程同时适用于32位和64位的Windows系统。1.从Oracle官网下载JDK-8最新Windows版下载地址:https://www.oracle.com/technetwork/java/javase/downloa......
  • python使用 flask+vue 制作前后端分离图书信息管理系统
    哈喽兄弟们,今天咱们来用Python实现一个前后端分离的图书信息管理系统。制作前后端分离图书信息管理系统的思路:1、前端部分首先,我们可以使用VueJS作为前端框架,并通过VueCLI工具进行创建和管理项目。2、后端部分后端部分我们可以采用PythonFlask框架,这个框......
  • 马尔科夫区制转移向量自回归模型,MSVAR模型,MS-VAR模型的GiveWin软件安装和操作过程+MS-
    马尔科夫区制转移向量自回归模型,MSVAR模型,MS-VAR模型的GiveWin软件安装和操作过程+MS-VAR各种图形制作(区制转换图、脉冲图、模型预测图和模型预测结果等等)+最优区制数和模型形式判断(MSI-VAR、MSM-VAR模型形式的最优选择问题,这是该模型的核心问题)。文档一共分为五部分,一是软件的安......
  • 使用优启通 制作 WIN PE U盘时报BOOT.WIM 有毒的解决方法
    使用优启通制作WINPEU盘时报BOOT.WIM有毒的解决方法 1.打开“WindowsDefender”.2.点击“病毒和威胁防护”。3.点击“管理设置”。4.点击“添加或删除排除项”。5.将“EasyU_v3.7.exe”添加到排除即可。6.双击EasyU_v3.7.exe,开始制作U盘。 ......
  • 直播平台制作,使用动画设置ProgressBar进度
    直播平台制作,使用动画设置ProgressBar进度布局文件: <?xmlversion="1.0"encoding="utf-8"?><LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:app="http://schemas.android.com/apk/res-auto"  ......