h5纯前端 简单做一个大小周计算器

公司实行大小周放假,经常因为节假日弄的有些混乱,在网上找一个样式很好看的时钟代码,加上日期和计算大小周,简单的制作一个大小周计算器.
大小周计算思路:选定某个是大周的周一,取当前时间戳减去选定的日期0点时间戳,模除两周的秒数,得出结果大于一周的秒数为小周,小于等于一周的秒数为大周.
代码比较简单,复制粘贴可用:
|
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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>山东微亮 大小周计算器</title> <style type="text/css"> @import url("https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400;500;700;900&display=swap"); *{margin:0;padding:0;list-style-type:none;} a,img{border:0;} :root { --purple-dark: #5F546E; --purple-light: #827593; --gray-light: #E5E3E8; --gray-dark: #A5A2A9; --light: #fcf8fb; --transition: all 150ms cubic-bezier(.46,1.13,.67,.87); } .clock-container { width: 405px; height: 150px; display: flex; align-items: center; justify-content: space-between; padding: 35px 50px; background-color: var(--purple-dark); position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); box-shadow: 0 15px 40px -10px rgba(0, 0, 0, 0.825); } .clock-container span { text-transform: uppercase; font-size: 10px; text-align: right; display: block; } .clock-container p { font-size: 60px; color: var(--light); font-weight: 100; } .clock-container p:first-letter { letter-spacing: 5px; } .container { width: 560px; height: 320px; display: block; box-shadow: 10px 10px 40px rgba(0, 0, 0, 0.215), -5px -5px 25px rgba(0, 0, 0, 0.125); background-color: var(--gray-light); position: relative; } .container .top { font-size: 25pt; width: 100%; text-align: center; justify-content: space-between; margin-top: 30px; } .container .bottom { height: 7px; width: 100%; position: absolute; bottom: 0; background-color: #aaa4b2; } .container .bottom .progress-bar { width: 240px; height: 100%; position: absolute; left: 0; bottom: 0; z-index: 9; background-color: #615770; transition: var(--transition); } .colon { --size: 3px; width: var(--size); height: 15px; position: relative; margin-left: 10px; margin-right: 10px; } .colon::before { content: ''; width: 100%; height: var(--size); background-color: #9892a3; position: absolute; top: 0; left: 0; border-radius: 50%; } .colon::after { content: ''; width: 100%; height: var(--size); background-color: #9892a3; position: absolute; bottom: 0; left: 0; border-radius: 50%; } .toast { width: 405px; color: var(--light); padding: 15px 24px; background-color: var(--purple-dark); position: absolute; bottom: -50px; left: 50%; transform: translateX(-50%); display: flex; justify-content: space-between; transition: var(--transition); z-index: 99; } .toast p { font-weight: 400; font-size: 18px; } .toast p:first-letter { text-transform: uppercase; } .toast.show { bottom: 50px; } .toast span { align-self: center; font-weight: 500; cursor: pointer; } *, *::before, *::after { box-sizing: border-box; } body { width: 100%; height: 100vh; padding: 0; margin: 0; overflow: hidden; color: var(--purple-light); background-color: var(--purple-light); display: flex; align-items: center; justify-content: center; font-family: 'Roboto', sans-serif; font-size: 16px; font-weight: 400; line-height: 1.15; position: relative; } </style> </head> <body> <div class="toast" data-type="pause"> <p>时钟已停止。</p><span>关闭</span> </div> <div class="toast" data-type="live"> <p>时钟现在是实时的。</p><span>关闭</span> </div> <div class="container"> <div class="top" id="top"> </div> <div class="clock-container"> <div class="hours"> <span>时</span> <p id="hour">00</p> </div> <div class="colon"></div> <div class="minutes"> <span>分</span> <p id="minute">00</p> </div> <div class="colon"></div> <div class="seconds"><span>秒</span> <p id="second">00</p> </div> </div> <div class="bottom"> <div class="progress-bar"></div> </div> </div> </body> <script type="text/javascript"> console.clear(); const hour = document.getElementById("hour"); const minute = document.getElementById("minute"); const second = document.getElementById("second"); const progress = document.querySelector(".progress-bar"); const pause = document.getElementById("pause"); const reset = document.getElementById("reset"); const toasts = document.getElementsByClassName("toast"); var interval; [...toasts].forEach(toast => { toast.addEventListener("click", hideToast); }); function hideToast(e) { const target = e.target; if (target.tagName.toUpperCase() === "SPAN") { target.parentNode.classList.remove("show"); } } function getCurrentTime() { const d = new Date(); let h = d.getHours(); let min = d.getMinutes(); let sec = d.getSeconds(); h = h < 10 ? "0" + h : h; min = min < 10 ? "0" + min : min; sec = sec < 10 ? "0" + sec : sec; hour.textContent = h; minute.textContent = min; second.textContent = sec; progress.style.width = +sec / 60 * 100 + "%"; } function clearClass(className) { for (let i = 0; i < toasts.length; i++) { toasts[i].classList.remove(className); } } interval = setInterval(getCurrentTime, 1000); function getBigWeek(){ //获取大小周 var timestamp = Date.parse(new Date())/1000-1614528000; if(timestamp%1209600<=604800){ return "?大周" }else{ return "?小周" } } function getDateWeek() { todayDate = new Date(); date = todayDate.getDate(); month = todayDate.getMonth() + 1; year = todayDate.getYear(); var dateweek = `<span style="font-size:5pt">`; if (navigator.appName == "Netscape") { dateweek = dateweek + (1900 + year) + "年" + month + "月" + date + "日 "; } if (navigator.appVersion.indexOf("MSIE") != -1) { dateweek = dateweek + year + "年" + month + "月" + date + "日 "; } switch (todayDate.getDay()) { case 0: dateweek += "星期日"; break; case 1: dateweek += "星期一"; break; case 2: dateweek += "星期二"; break; case 3: dateweek += "星期三"; break; case 4: dateweek += "星期四"; break; case 5: dateweek += "星期五"; break; case 6: dateweek += "星期六"; break; } dateweek+="</span> "+getBigWeek() return dateweek; } document.getElementById("top").innerHTML=getDateWeek() </script> </html> |