|
@@ -0,0 +1,557 @@
|
|
1
|
+<!--
|
|
2
|
+ * @Author: ysh
|
|
3
|
+ * @Date: 2024-03-07 10:00:26
|
|
4
|
+ * @LastEditors: Please set LastEditors
|
|
5
|
+ * @LastEditTime: 2024-03-07 10:14:41
|
|
6
|
+-->
|
|
7
|
+
|
|
8
|
+<template>
|
|
9
|
+ <div class="contianer">
|
|
10
|
+ <div class="calendar">
|
|
11
|
+ <div class="calendar-header">
|
|
12
|
+ <span class="month-picker" id="month-picker"> May </span>
|
|
13
|
+ <div class="year-picker" id="year-picker">
|
|
14
|
+ <span class="year-change" id="pre-year">
|
|
15
|
+ <pre><</pre>
|
|
16
|
+ </span>
|
|
17
|
+ <span id="year">2020 </span>
|
|
18
|
+ <span class="year-change" id="next-year">
|
|
19
|
+ <pre>></pre>
|
|
20
|
+ </span>
|
|
21
|
+ </div>
|
|
22
|
+ </div>
|
|
23
|
+
|
|
24
|
+ <div class="calendar-body">
|
|
25
|
+ <div class="calendar-week-days">
|
|
26
|
+ <div>Sun</div>
|
|
27
|
+ <div>Mon</div>
|
|
28
|
+ <div>Tue</div>
|
|
29
|
+ <div>Wed</div>
|
|
30
|
+ <div>Thu</div>
|
|
31
|
+ <div>Fri</div>
|
|
32
|
+ <div>Sat</div>
|
|
33
|
+ </div>
|
|
34
|
+ <div class="calendar-days">
|
|
35
|
+ </div>
|
|
36
|
+ </div>
|
|
37
|
+ <div class="calendar-footer">
|
|
38
|
+ </div>
|
|
39
|
+ <div class="date-time-formate">
|
|
40
|
+ <div class="day-text-formate">TODAY</div>
|
|
41
|
+ <div class="date-time-value">
|
|
42
|
+ <div class="time-formate">02:51:20</div>
|
|
43
|
+ <div class="date-formate">23 - july - 2022</div>
|
|
44
|
+ </div>
|
|
45
|
+ </div>
|
|
46
|
+ <div class="month-list"></div>
|
|
47
|
+ </div>
|
|
48
|
+ </div>
|
|
49
|
+</template>
|
|
50
|
+
|
|
51
|
+<script>
|
|
52
|
+export default {
|
|
53
|
+ name: 'Calendar',
|
|
54
|
+ mounted() {
|
|
55
|
+ this.initCalendar();
|
|
56
|
+ },
|
|
57
|
+ methods: {
|
|
58
|
+ initCalendar() {
|
|
59
|
+ const isLeapYear = (year) => {
|
|
60
|
+ return (
|
|
61
|
+ (year % 4 === 0 && year % 100 !== 0 && year % 400 !== 0) ||
|
|
62
|
+ (year % 100 === 0 && year % 400 === 0)
|
|
63
|
+ );
|
|
64
|
+ };
|
|
65
|
+ const getFebDays = (year) => {
|
|
66
|
+ return isLeapYear(year) ? 29 : 28;
|
|
67
|
+ };
|
|
68
|
+ let calendar = document.querySelector('.calendar');
|
|
69
|
+ const month_names = [
|
|
70
|
+ 'January',
|
|
71
|
+ 'February',
|
|
72
|
+ 'March',
|
|
73
|
+ 'April',
|
|
74
|
+ 'May',
|
|
75
|
+ 'June',
|
|
76
|
+ 'July',
|
|
77
|
+ 'August',
|
|
78
|
+ 'September',
|
|
79
|
+ 'October',
|
|
80
|
+ 'November',
|
|
81
|
+ 'December',
|
|
82
|
+ ];
|
|
83
|
+ let month_picker = document.querySelector('#month-picker');
|
|
84
|
+ const dayTextFormate = document.querySelector('.day-text-formate');
|
|
85
|
+ const timeFormate = document.querySelector('.time-formate');
|
|
86
|
+ const dateFormate = document.querySelector('.date-formate');
|
|
87
|
+
|
|
88
|
+ month_picker.onclick = () => {
|
|
89
|
+ month_list.classList.remove('hideonce');
|
|
90
|
+ month_list.classList.remove('hide');
|
|
91
|
+ month_list.classList.add('show');
|
|
92
|
+ dayTextFormate.classList.remove('showtime');
|
|
93
|
+ dayTextFormate.classList.add('hidetime');
|
|
94
|
+ timeFormate.classList.remove('showtime');
|
|
95
|
+ timeFormate.classList.add('hideTime');
|
|
96
|
+ dateFormate.classList.remove('showtime');
|
|
97
|
+ dateFormate.classList.add('hideTime');
|
|
98
|
+ };
|
|
99
|
+
|
|
100
|
+ const generateCalendar = (month, year) => {
|
|
101
|
+ let calendar_days = document.querySelector('.calendar-days');
|
|
102
|
+ calendar_days.innerHTML = '';
|
|
103
|
+ let calendar_header_year = document.querySelector('#year');
|
|
104
|
+ let days_of_month = [
|
|
105
|
+ 31,
|
|
106
|
+ getFebDays(year),
|
|
107
|
+ 31,
|
|
108
|
+ 30,
|
|
109
|
+ 31,
|
|
110
|
+ 30,
|
|
111
|
+ 31,
|
|
112
|
+ 31,
|
|
113
|
+ 30,
|
|
114
|
+ 31,
|
|
115
|
+ 30,
|
|
116
|
+ 31,
|
|
117
|
+ ];
|
|
118
|
+
|
|
119
|
+ let currentDate = new Date();
|
|
120
|
+
|
|
121
|
+ month_picker.innerHTML = month_names[month];
|
|
122
|
+
|
|
123
|
+ calendar_header_year.innerHTML = year;
|
|
124
|
+
|
|
125
|
+ let first_day = new Date(year, month);
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+ for (let i = 0; i <= days_of_month[month] + first_day.getDay() - 1; i++) {
|
|
129
|
+
|
|
130
|
+ let day = document.createElement('div');
|
|
131
|
+
|
|
132
|
+ if (i >= first_day.getDay()) {
|
|
133
|
+ day.innerHTML = i - first_day.getDay() + 1;
|
|
134
|
+
|
|
135
|
+ if (i - first_day.getDay() + 1 === currentDate.getDate() &&
|
|
136
|
+ year === currentDate.getFullYear() &&
|
|
137
|
+ month === currentDate.getMonth()
|
|
138
|
+ ) {
|
|
139
|
+ day.classList.add('current-date');
|
|
140
|
+ }
|
|
141
|
+ }
|
|
142
|
+ calendar_days.appendChild(day);
|
|
143
|
+ }
|
|
144
|
+ };
|
|
145
|
+
|
|
146
|
+ let month_list = calendar.querySelector('.month-list');
|
|
147
|
+ month_names.forEach((e, index) => {
|
|
148
|
+ let month = document.createElement('div');
|
|
149
|
+ month.innerHTML = `<div>${e}</div>`;
|
|
150
|
+
|
|
151
|
+ month_list.append(month);
|
|
152
|
+ month.onclick = () => {
|
|
153
|
+ currentMonth.value = index;
|
|
154
|
+ generateCalendar(currentMonth.value, currentYear.value);
|
|
155
|
+ month_list.classList.replace('show', 'hide');
|
|
156
|
+ dayTextFormate.classList.remove('hideTime');
|
|
157
|
+ dayTextFormate.classList.add('showtime');
|
|
158
|
+ timeFormate.classList.remove('hideTime');
|
|
159
|
+ timeFormate.classList.add('showtime');
|
|
160
|
+ dateFormate.classList.remove('hideTime');
|
|
161
|
+ dateFormate.classList.add('showtime');
|
|
162
|
+ };
|
|
163
|
+ });
|
|
164
|
+
|
|
165
|
+ (function () {
|
|
166
|
+ month_list.classList.add('hideonce');
|
|
167
|
+ })();
|
|
168
|
+ document.querySelector('#pre-year').onclick = () => {
|
|
169
|
+ --currentYear.value;
|
|
170
|
+ generateCalendar(currentMonth.value, currentYear.value);
|
|
171
|
+ };
|
|
172
|
+ document.querySelector('#next-year').onclick = () => {
|
|
173
|
+ ++currentYear.value;
|
|
174
|
+ generateCalendar(currentMonth.value, currentYear.value);
|
|
175
|
+ };
|
|
176
|
+
|
|
177
|
+ let currentDate = new Date();
|
|
178
|
+ let currentMonth = { value: currentDate.getMonth() };
|
|
179
|
+ let currentYear = { value: currentDate.getFullYear() };
|
|
180
|
+ generateCalendar(currentMonth.value, currentYear.value);
|
|
181
|
+
|
|
182
|
+ const todayShowTime = document.querySelector('.time-formate');
|
|
183
|
+ const todayShowDate = document.querySelector('.date-formate');
|
|
184
|
+
|
|
185
|
+ const currshowDate = new Date();
|
|
186
|
+ const showCurrentDateOption = {
|
|
187
|
+ year: 'numeric',
|
|
188
|
+ month: 'long',
|
|
189
|
+ day: 'numeric',
|
|
190
|
+ weekday: 'long',
|
|
191
|
+ };
|
|
192
|
+ const currentDateFormate = new Intl.DateTimeFormat(
|
|
193
|
+ 'en-US',
|
|
194
|
+ showCurrentDateOption
|
|
195
|
+ ).format(currshowDate);
|
|
196
|
+ todayShowDate.textContent = currentDateFormate;
|
|
197
|
+ setInterval(() => {
|
|
198
|
+ const timer = new Date();
|
|
199
|
+ const option = {
|
|
200
|
+ hour: 'numeric',
|
|
201
|
+ minute: 'numeric',
|
|
202
|
+ second: 'numeric',
|
|
203
|
+ };
|
|
204
|
+ const formateTimer = new Intl.DateTimeFormat('en-us', option).format(timer);
|
|
205
|
+ let time = `${`${timer.getHours()}`.padStart(
|
|
206
|
+ 2,
|
|
207
|
+ '0'
|
|
208
|
+ )}:${`${timer.getMinutes()}`.padStart(
|
|
209
|
+ 2,
|
|
210
|
+ '0'
|
|
211
|
+ )}: ${`${timer.getSeconds()}`.padStart(2, '0')}`;
|
|
212
|
+ todayShowTime.textContent = formateTimer;
|
|
213
|
+ }, 1000);
|
|
214
|
+
|
|
215
|
+ }
|
|
216
|
+ },
|
|
217
|
+}
|
|
218
|
+</script>
|
|
219
|
+
|
|
220
|
+<style lang="scss">
|
|
221
|
+:root {
|
|
222
|
+ --dark-text: #f8fbff;
|
|
223
|
+ --light-body: #f3f8fe;
|
|
224
|
+ --light-main: #fdfdfd;
|
|
225
|
+ --light-second: #c3c2c8;
|
|
226
|
+ --light-hover: #f0f0f0;
|
|
227
|
+ --light-text: #151426;
|
|
228
|
+ --light-btn: #9796f0;
|
|
229
|
+ --blue: #0000ff;
|
|
230
|
+ --white: #fff;
|
|
231
|
+ --shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
|
|
232
|
+ --font-family: consolas;
|
|
233
|
+}
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+.contianer {
|
|
237
|
+ width: max-content;
|
|
238
|
+ height: max-content;
|
|
239
|
+ position: relative;
|
|
240
|
+ display: flex;
|
|
241
|
+ padding: 2% 0px 0px 0px;
|
|
242
|
+ justify-content: center;
|
|
243
|
+ top: 10%;
|
|
244
|
+ right: 0%;
|
|
245
|
+ width: 100%;
|
|
246
|
+ height: 100%;
|
|
247
|
+}
|
|
248
|
+
|
|
249
|
+.calendar {
|
|
250
|
+ // height: 610px;
|
|
251
|
+ width: max-content;
|
|
252
|
+ background-color: white;
|
|
253
|
+ border-radius: 25px;
|
|
254
|
+ overflow: hidden;
|
|
255
|
+ padding: 30px 50px 0px 50px;
|
|
256
|
+}
|
|
257
|
+
|
|
258
|
+.calendar {
|
|
259
|
+ box-shadow: var(--shadow);
|
|
260
|
+}
|
|
261
|
+
|
|
262
|
+.calendar-header {
|
|
263
|
+ background: #9796f0;
|
|
264
|
+ display: flex;
|
|
265
|
+ justify-content: space-between;
|
|
266
|
+ align-items: center;
|
|
267
|
+ font-weight: 700;
|
|
268
|
+ color: var(--white);
|
|
269
|
+ padding: 10px;
|
|
270
|
+}
|
|
271
|
+
|
|
272
|
+.calendar-body {
|
|
273
|
+ pad: 10px;
|
|
274
|
+}
|
|
275
|
+
|
|
276
|
+.calendar-week-days {
|
|
277
|
+ display: grid;
|
|
278
|
+ grid-template-columns: repeat(7, 1fr);
|
|
279
|
+ font-weight: 600;
|
|
280
|
+ cursor: pointer;
|
|
281
|
+ color: rgb(104, 104, 104);
|
|
282
|
+}
|
|
283
|
+
|
|
284
|
+.calendar-week-days div:hover {
|
|
285
|
+ color: black;
|
|
286
|
+ transform: scale(1.2);
|
|
287
|
+ transition: all .2s ease-in-out;
|
|
288
|
+}
|
|
289
|
+
|
|
290
|
+.calendar-week-days div {
|
|
291
|
+ display: grid;
|
|
292
|
+ place-items: center;
|
|
293
|
+ color: var(--bg-second);
|
|
294
|
+ height: 50px;
|
|
295
|
+}
|
|
296
|
+
|
|
297
|
+.calendar-days {
|
|
298
|
+ display: grid;
|
|
299
|
+ grid-template-columns: repeat(7, 1fr);
|
|
300
|
+ gap: 2px;
|
|
301
|
+ color: var(--color-txt);
|
|
302
|
+}
|
|
303
|
+
|
|
304
|
+.calendar-days div {
|
|
305
|
+ width: 37px;
|
|
306
|
+ height: 33px;
|
|
307
|
+ display: flex;
|
|
308
|
+ align-items: center;
|
|
309
|
+ justify-content: center;
|
|
310
|
+ padding: 5px;
|
|
311
|
+ position: relative;
|
|
312
|
+ cursor: pointer;
|
|
313
|
+ animation: to-top 1s forwards;
|
|
314
|
+}
|
|
315
|
+
|
|
316
|
+.month-picker {
|
|
317
|
+ padding: 5px 10px;
|
|
318
|
+ border-radius: 10px;
|
|
319
|
+ cursor: pointer;
|
|
320
|
+}
|
|
321
|
+
|
|
322
|
+.month-picker:hover {
|
|
323
|
+ background-color: var(--color-hover);
|
|
324
|
+}
|
|
325
|
+
|
|
326
|
+.month-picker:hover {
|
|
327
|
+ color: var(--color-txt);
|
|
328
|
+}
|
|
329
|
+
|
|
330
|
+.year-picker {
|
|
331
|
+ display: flex;
|
|
332
|
+ align-items: center;
|
|
333
|
+}
|
|
334
|
+
|
|
335
|
+.year-change {
|
|
336
|
+ height: 30px;
|
|
337
|
+ width: 30px;
|
|
338
|
+ border-radius: 50%;
|
|
339
|
+ display: grid;
|
|
340
|
+ place-items: center;
|
|
341
|
+ margin: 0px 10px;
|
|
342
|
+ cursor: pointer;
|
|
343
|
+}
|
|
344
|
+
|
|
345
|
+.year-change:hover {
|
|
346
|
+ background-color: var(--light-btn);
|
|
347
|
+ transition: all .2s ease-in-out;
|
|
348
|
+ transform: scale(1.12);
|
|
349
|
+}
|
|
350
|
+
|
|
351
|
+.year-change:hover pre {
|
|
352
|
+ color: var(--bg-body);
|
|
353
|
+}
|
|
354
|
+
|
|
355
|
+.calendar-footer {
|
|
356
|
+ padding: 10px;
|
|
357
|
+ display: flex;
|
|
358
|
+ justify-content: flex-end;
|
|
359
|
+ align-items: center;
|
|
360
|
+}
|
|
361
|
+
|
|
362
|
+#year:hover {
|
|
363
|
+ cursor: pointer;
|
|
364
|
+ transform: scale(1.2);
|
|
365
|
+ transition: all 0.2 ease-in-out;
|
|
366
|
+}
|
|
367
|
+
|
|
368
|
+.calendar-days div span {
|
|
369
|
+ position: absolute;
|
|
370
|
+}
|
|
371
|
+
|
|
372
|
+.calendar-days div:hover {
|
|
373
|
+ transition: width 0.2s ease-in-out, height 0.2s ease-in-out;
|
|
374
|
+ background-color: #fbc7d4;
|
|
375
|
+ border-radius: 20%;
|
|
376
|
+ color: var(--dark-text);
|
|
377
|
+}
|
|
378
|
+
|
|
379
|
+.calendar-days div.current-date {
|
|
380
|
+ color: var(--dark-text);
|
|
381
|
+ background-color: var(--light-btn);
|
|
382
|
+ border-radius: 20%;
|
|
383
|
+}
|
|
384
|
+
|
|
385
|
+.month-list {
|
|
386
|
+ position: relative;
|
|
387
|
+ left: 0;
|
|
388
|
+ top: -50px;
|
|
389
|
+ background-color: #ebebeb;
|
|
390
|
+ color: var(--light-text);
|
|
391
|
+ display: grid;
|
|
392
|
+ grid-template-columns: repeat(3, auto);
|
|
393
|
+ gap: 5px;
|
|
394
|
+ border-radius: 20px;
|
|
395
|
+}
|
|
396
|
+
|
|
397
|
+.month-list>div {
|
|
398
|
+ display: grid;
|
|
399
|
+ place-content: center;
|
|
400
|
+ margin: 5px 10px;
|
|
401
|
+ transition: all 0.2s ease-in-out;
|
|
402
|
+}
|
|
403
|
+
|
|
404
|
+.month-list>div>div {
|
|
405
|
+ border-radius: 15px;
|
|
406
|
+ padding: 10px;
|
|
407
|
+ cursor: pointer;
|
|
408
|
+}
|
|
409
|
+
|
|
410
|
+.month-list>div>div:hover {
|
|
411
|
+ background-color: var(--light-btn);
|
|
412
|
+ color: var(--dark-text);
|
|
413
|
+ transform: scale(0.9);
|
|
414
|
+ transition: all 0.2s ease-in-out;
|
|
415
|
+}
|
|
416
|
+
|
|
417
|
+.month-list.show {
|
|
418
|
+ visibility: visible;
|
|
419
|
+ pointer-events: visible;
|
|
420
|
+ transition: 0.6s ease-in-out;
|
|
421
|
+ animation: to-left .71s forwards;
|
|
422
|
+}
|
|
423
|
+
|
|
424
|
+.month-list.hideonce {
|
|
425
|
+ visibility: hidden;
|
|
426
|
+}
|
|
427
|
+
|
|
428
|
+.month-list.hide {
|
|
429
|
+ animation: to-right 1s forwards;
|
|
430
|
+ visibility: none;
|
|
431
|
+ pointer-events: none;
|
|
432
|
+}
|
|
433
|
+
|
|
434
|
+.date-time-formate {
|
|
435
|
+ width: max-content;
|
|
436
|
+ height: max-content;
|
|
437
|
+ font-family: Dubai Light, Century Gothic;
|
|
438
|
+ position: relative;
|
|
439
|
+ display: inline;
|
|
440
|
+ top: 140px;
|
|
441
|
+ justify-content: center;
|
|
442
|
+}
|
|
443
|
+
|
|
444
|
+.day-text-formate {
|
|
445
|
+ font-family: Microsoft JhengHei UI;
|
|
446
|
+ font-size: 1.4rem;
|
|
447
|
+ padding-right: 5%;
|
|
448
|
+ border-right: 3px solid #9796f0;
|
|
449
|
+ position: absolute;
|
|
450
|
+ left: -1rem;
|
|
451
|
+}
|
|
452
|
+
|
|
453
|
+.date-time-value {
|
|
454
|
+ display: block;
|
|
455
|
+ height: max-content;
|
|
456
|
+ width: max-content;
|
|
457
|
+ position: relative;
|
|
458
|
+ left: 40%;
|
|
459
|
+ top: -18px;
|
|
460
|
+ text-align: center;
|
|
461
|
+}
|
|
462
|
+
|
|
463
|
+.time-formate {
|
|
464
|
+ font-size: 1.5rem;
|
|
465
|
+}
|
|
466
|
+
|
|
467
|
+.time-formate.hideTime {
|
|
468
|
+ animation: hidetime 1.5s forwards;
|
|
469
|
+}
|
|
470
|
+
|
|
471
|
+.day-text-formate.hidetime {
|
|
472
|
+ animation: hidetime 1.5s forwards;
|
|
473
|
+}
|
|
474
|
+
|
|
475
|
+.date-formate.hideTime {
|
|
476
|
+ animation: hidetime 1.5s forwards;
|
|
477
|
+}
|
|
478
|
+
|
|
479
|
+.day-text-formate.showtime {
|
|
480
|
+ animation: showtime 1s forwards;
|
|
481
|
+}
|
|
482
|
+
|
|
483
|
+.time-formate.showtime {
|
|
484
|
+ animation: showtime 1s forwards;
|
|
485
|
+}
|
|
486
|
+
|
|
487
|
+.date-formate.showtime {
|
|
488
|
+ animation: showtime 1s forwards;
|
|
489
|
+}
|
|
490
|
+
|
|
491
|
+@keyframes to-top {
|
|
492
|
+ 0% {
|
|
493
|
+ transform: translateY(0);
|
|
494
|
+ opacity: 0;
|
|
495
|
+ }
|
|
496
|
+
|
|
497
|
+ 100% {
|
|
498
|
+ transform: translateY(100%);
|
|
499
|
+ opacity: 1;
|
|
500
|
+ }
|
|
501
|
+}
|
|
502
|
+
|
|
503
|
+@keyframes to-left {
|
|
504
|
+ 0% {
|
|
505
|
+ transform: translatex(230%);
|
|
506
|
+ opacity: 1;
|
|
507
|
+ }
|
|
508
|
+
|
|
509
|
+ 100% {
|
|
510
|
+ transform: translatex(0);
|
|
511
|
+ opacity: 1;
|
|
512
|
+ }
|
|
513
|
+}
|
|
514
|
+
|
|
515
|
+@keyframes to-right {
|
|
516
|
+ 10% {
|
|
517
|
+ transform: translatex(0);
|
|
518
|
+ opacity: 1;
|
|
519
|
+ }
|
|
520
|
+
|
|
521
|
+ 100% {
|
|
522
|
+ transform: translatex(-150%);
|
|
523
|
+ opacity: 1;
|
|
524
|
+ }
|
|
525
|
+}
|
|
526
|
+
|
|
527
|
+@keyframes showtime {
|
|
528
|
+ 0% {
|
|
529
|
+ transform: translatex(250%);
|
|
530
|
+ opacity: 1;
|
|
531
|
+ }
|
|
532
|
+
|
|
533
|
+ 100% {
|
|
534
|
+ transform: translatex(0%);
|
|
535
|
+ opacity: 1;
|
|
536
|
+ }
|
|
537
|
+}
|
|
538
|
+
|
|
539
|
+@keyframes hidetime {
|
|
540
|
+ 0% {
|
|
541
|
+ transform: translatex(0%);
|
|
542
|
+ opacity: 1;
|
|
543
|
+ }
|
|
544
|
+
|
|
545
|
+ 100% {
|
|
546
|
+ transform: translatex(-370%);
|
|
547
|
+ opacity: 1;
|
|
548
|
+ }
|
|
549
|
+}
|
|
550
|
+
|
|
551
|
+@media (max-width:375px) {
|
|
552
|
+ .month-list>div {
|
|
553
|
+
|
|
554
|
+ margin: 5px 0px;
|
|
555
|
+ }
|
|
556
|
+}
|
|
557
|
+</style>
|