给博客添加一个时钟效果
文章摘要
MxGPT
折腾博客脚步永不停止,一切折腾从魔改开始!由于我准备把侧边栏时钟功能移除掉了,但是之前魔改的代码还是想留着,所以有了本文,爱折腾,有兴趣的可以尝试一下!
此内容根据文章生成,并经过人工审核,仅用于文章内容的解释与总结
投诉折腾博客脚步永不停止,一切折腾从魔改开始!
由于我准备把侧边栏时钟功能移除掉了,但是之前魔改的代码还是想留着,所以有了本文,爱折腾,有兴趣的可以尝试一下!
效果预览
效果预览
魔改步骤
魔改步骤
- 新建card_clock.pug,添加如下内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170if theme.aside.card_clock.enable
style.
.clock_frame {
background: var(--Jay-main);
display: flex;
justify-content: center;
align-content: center;
box-shadow: var(--Jay-shadow-border);
background: var(--Jay-card-bg);
border: var(--style-border);
border-radius: 12px;
transition: .3s;
position: relative;
overflow: hidden;
margin-top: 1rem;
}
.clock {
width: 256px;
height: 256px;
border-radius: 50%;
background-color: #fff;
position: relative;
overflow: hidden;
}
.clock::after {
content: "";
width: calc(256px - 80px);
height: calc(256px - 80px);
background-color: inherit;
border-radius: 50%;
display: block;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
}
.clock .marker {
height: calc(100% - 25px);
width: 3.2px;
background-color: rgb(52 73 94 / 40%);
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
}
.clock .marker:nth-of-type(3n + 1) {
background: rgb(52 73 94);
}
.clock .marker:nth-of-type(2) {
transform: rotate(30deg);
}
.clock .marker:nth-of-type(3) {
transform: rotate(60deg);
}
.clock .marker:nth-of-type(4) {
transform: rotate(90deg);
}
.clock .marker:nth-of-type(5) {
transform: rotate(120deg);
}
.clock .marker:nth-of-type(6) {
transform: rotate(150deg);
}
.clock .hand {
transform-origin: center bottom;
position: absolute;
z-index: 3;
bottom: 50%;
left: 50%;
width: 5.12px;
transition: transform 1s linear;
}
.clock .hand.second {
height: 85.3333333333px;
width: 1.3837837838px;
left: calc(50% - 1.5px);
border-radius: 1.5px;
background-color: #ec231e;
box-shadow: 4px 6px 0 0 rgba(0, 0, 0, 0.15);
transform: rotate(40deg);
z-index: 9;
}
.clock .hand.second::before,
.clock .hand.second::after {
content: "";
background-color: inherit;
position: absolute;
border-radius: 50%;
left: 50%;
}
.clock .hand.second::before {
width: 12.8px;
height: 12.8px;
bottom: 0;
transform: translate(-50%, 50%);
box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.15);
}
.clock .hand.second::after {
width: 7.1111111111px;
height: 7.1111111111px;
top: 17.0666666667px;
transform: translate(-50%, 0);
box-shadow: 4px 6px 2px 0 rgba(0, 0, 0, 0.15);
}
.clock .hand.minute {
height: 85.3333333333px;
left: calc(50% - 3px);
border-radius: 3px;
background-color: rgb(52 73 94);
}
.clock .hand.hour {
height: 64px;
left: calc(50% - 3px);
border-radius: 3px;
background-color: rgb(52 73 94);
}
@media screen and (max-width: 768px) {
.clock_frame {
display: none;
}
}
@-webkit-keyframes rotateArms {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
@keyframes rotateArms {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
.cat_block.clock_frame
.clock
.marker
.marker
.marker
.marker
.marker
.marker
.hand.second
.hand.minute
.hand.hour
script.
let secondPlus = 0;
function getTime() {
let date = new Date(),
seconds = date.getSeconds() * 6,
minutes = date.getMinutes() * 6,
hours = (date.getHours() % 12) * 30 + minutes / 15;
if (seconds == 0) {
secondPlus += 360;
}
document.querySelector(".hand.second").style.transform = "rotate( " + (seconds + secondPlus) + "deg)";
document.querySelector(".hand.minute").style.transform = "rotate( " + minutes + "deg)";
document.querySelector(".hand.hour").style.transform = "rotate( " + hours + "deg)";
}
setInterval(function() {
getTime();
}, 1000); - 在 theme\layout\includes\widget\index.pug 中的侧边栏引入
1
2//- 时钟
!=partial('includes/widget/card_clock', {}, {cache: true}) - 主题配置文件_config.mxblog.yml添加开关
1
2
3aside:
card_clock:
enable: true # 时钟
至此,你的侧边栏将多了一个时钟,快去试试吧!
- 感谢你赐予我前进的力量
打赏者名单
因为你们的支持让我意识到写文章的价值🙏
本文是原创文章,采用CC BY-NC-ND 4.0协议,完整转载请注明来自满心记
评论
匿名评论
隐私政策
✅ 你无需删除空行,直接评论以获取最佳展示效果