前端快速学习记录:实现一个原神时钟(简易版)

 正在学习React,今天先快速学一下前端页面的一些基础知识,并做一个小实践。上面是实现时钟的展示。(做得可能不够好,与原版的还是有许多差距,全当是玩)

前端实现分为html元素布局代码+css样式代码+js逻辑代码

1.html部分 

页面由html文件来展示,html负责设计元素的布局(位置关系)

本次实践使用到的标签:

1. 文档框架:html,head,body,title

2. 编码设置:meta

3. 代码块标签: script

4. 链接标签:link

5. 容器标签:div

6. 其他标签:label(用来显示时钟的每一个部分)

每一个标签在文本中,构成一个个的元素,元素含有各自的属性,常用属性包括

class:将元素进行分类,便于统一管理,可以属于多个类别

id:每个元素的唯一标识,便于对特定元素的获取

href:相对链接,以当前文档的url为基准的链接路径

rel:关系属性,定义文件与链接的关系

src:外部资源属性,设置所引用的外部资源文件url

2.CSS部分 

CSS样式表,部分基本语法:

 选择器(负责筛选需要设置样式的元素):类选择器、id选择器、全局选择器、标签选择器

举例:

常见选择器
选择器例子描述
.class.intro选择 class="intro" 的所有元素。
.class1.class2.name1.name2选择 class 属性中同时有 name1 和 name2 的所有元素。
.class1 .class2.name1 .name2选择作为类名 name1 元素后代的所有类名 name2 元素。
#id#firstname选择 id="firstname" 的元素。
**选择所有元素。
elementp选择所有 <p> 元素。
element.classp.intro选择 class="intro" 的所有 <p> 元素。
element,elementdiv, p选择所有 <div> 元素和所有 <p> 元素。
element elementdiv p选择 <div> 元素内的所有 <p> 元素。
element>elementdiv > p选择父元素是 <div> 的所有 <p> 元素。
[attribute][target]选择带有 target 属性的所有元素。
:activea:active选择活动链接。
::afterp::after在每个 <p> 的内容之后插入内容。类推
:root:root选择文档的根元素。
:not(selector):not(p)选择非 <p> 元素的每个元素。

 筛选出元素后,进行设置属性

        例子:

.container{
    position: relative;
    text-align: center;
    width: 500px;
    height: 500px;
    background: #83D0BC;
    margin: auto;
    display: flex;
}

属性:

1.使用相对位置

2.设置其内容文本行居中

3.4. 设置其宽高

5. 设置背景色

6.自动外边距(居中)

7.弹性布局

 3.js部分

控制指针的转动(控制分针,时钟同理就懒得实现了)

let minute = document.getElementById("minute")
let count = 0
let timer = setInterval(function (){
    minute.style.transform = "rotate("+(180+count*6)+"deg)"
    count += 1
    count %= 60
}, 1000)

4.完整源文件 

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>GenShin Clock</title>
    <script src="cfg/16.4.0/react-dom.development.js"></script>
    <script src="cfg/16.4.0/react.development.js"></script>
    <script src="cfg/16.4.0/babel.min.js"></script>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container", id="can">
        <label class="clock_unit clock_bg"></label>
        <label class="clock_unit clock_hbg"></label>
        <label class="clock_unit star_particles"></label>
        <label class="clock_unit clock_horoscope04"></label>
        <label class="clock_unit clock_horoscope03"></label>
        <label class="clock_unit clock_horoscope06"></label>
        <label class="clock_unit clock_horoscope05"></label>
        <label class="clock_unit clock_dial"></label>
        <ClockHand class="clock_unit clock_hourHand" id="hour"></ClockHand>
        <label class="clock_unit clock_minuteHand" id="minute"></label>
        <label class="sun_state morning"></label>
        <label class="sun_state dusk"></label>
        <label class="sun_state night"></label>
        <label class="sun_state Noon"></label>
    </div>
    <script type="text/babel" src="script.js"></script>
</body>
</html>
body{
    background: #7acbeb;
    display: flex;
}
.container{
    position: relative;
    text-align: center;
    width: 500px;
    height: 500px;
    background: #83D0BC;
    margin: auto;
    display: flex;
}

.clock_unit{
    position: absolute;
    width: 500px;
    height: 500px;
    left: 0;
    top: 0;
    background: rgba(100, 80, 120, 0.2);
    text-align: center;
}

.clock_bg{
    background: url("images/Clock_BG.png");
    background-size: 100%, 100%;
}

.clock_hbg{
    background: url("images/UI_Img_HoroscopeBg.png");
    background-size: 100%, 100%;
}

.star_particles{
    background: url("images/star_particles.gif");
    background-size: 100%, 100%;
}

.clock_dial{
    background: url("images/UI_Clock_Dial.png");
    background-size: 100%, 100%;
}

.clock_horoscope03{
    background: url("images/UI_Img_Horoscope03.png") no-repeat;
    background-size: 68%, 68%;
    width: 425px;
    height: 425px;
    left: 45px;
    top: 130px;
    transform: rotate(40deg);
}

.clock_horoscope04{
    background: url("images/UI_Img_Horoscope04.png") no-repeat;
    transform: rotate(40deg);
    background-size: 47%;
    width: 425px;
    height: 425px;
    left: 32px;
    top: 195px;
    offset-position: 32px 195px;
}

.clock_hourHand{
    background: url("images/UI_Clock_HourHand.png");
    transform: rotate(45deg);
    background-size: 100%, 100%;
}

.clock_minuteHand{
    background: url("images/UI_Clock_MinuteHand.png");
    transform: rotate(180deg);
    background-size: 100%, 100%;
}

let minute = document.getElementById("minute")
let count = 0
let timer = setInterval(function (){
    minute.style.transform = "rotate("+(180+count*6)+"deg)"
    count += 1
    count %= 60
}, 1000)

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

尼卡尼卡尼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值