点名系统
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>点名系统</title>
<style type="text/css">
* {
font-family: "微软雅黑";
}
h1,
h2 {
animation: changeColor 2s linear infinite;
animation-direction: alternate;
}
h1 {
background-color: yellowgreen;
color: white;
text-align: center;
}
#content>div {
float: left;
width: 100px;
height: 50px;
margin: 5px;
font-size: 20px;
line-height: 50px;
text-align: center;
}
.cell {
background-color: black;
color: white;
}
.current {
background-color: greenyellow;
color: blueviolet;
}
button {
display: inline-block;
height: 50px;
background-color: yellowgreen;
color: white;
font-size: 16px;
margin: 10px;
}
select {
display: inline-block;
height: 30px;
width: 100px;
border: 1px solid yellowgreen;
background-color: blanchedalmond;
color: black;
font-size: 14px;
margin: 10px;
}
@keyframes changeColor {
from {
color: pink;
}
to {
color: blueviolet;
}
}
</style>
</head>
<body>
<h1>点名系统</h1>
<h2 id="selectTitle">被选中的小伙伴:</h2>
<button onclick="go()">开始</button>
时间:
<select id="sele">
<option value="10" selected>10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
<option value="50">50</option>
</select>
<div id="content"></div>
</body>
<script src="../js/callnames2.js"></script>
</html>
const names = ['成庆', '宋华全', '谭志成', '陈凝斌', '林培根', '杨镇', '詹兴杜', '连晓东', '邓旭湘', '麦云景', '石欣锜', '周维', '梁坤', '刘猛', '钟荣', '李昆泉', '龙志东', '蔡敏芳', '廖璐', '许国栋', '周裕涛', '孔创立', '黎炜扬', '蒋茂春', '袁谷音', '陈新裕', '张译文', '彭称枰', '周巧', '梁颖波', '尹美凤', '王浩', '黄家俊', '陈沛全', '麦婉莹', '刘明亮', '陈乐贤', '钟杰', '柯耿明', '张云云', '何育焯', '陈龙光', '周文杰', '张金波', '谢玉山', '梁仕俊', '李旭阳', '黄俊标', '刘家益', '陈光钰']
const selectTitle = document.querySelector('#selectTitle')
const sele = document.querySelector('#sele')
const btn = document.querySelector('button')
const content = document.querySelector('#content')
content.innerHTML = names.map(function (item) {
return `<div class="cell">${item}</div>`
}).join('')
function go() {
btn.onclick = null
let time = sele[sele.selectedIndex].value - 0
let count = 0
let index = -1
const cells = content.querySelectorAll(':not(.current)')
let timeId = setInterval(function () {
count++
cells[index] && cells[index].classList.remove('current')
index = Math.floor(Math.random() * cells.length)
cells[index].classList.add('current')
if (count == time) {
clearInterval(timeId)
selectTitle.innerHTML += ` ${cells[index].innerText}`
btn.onclick = go
}
}, 100)
}
打地鼠
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Whack A Mole!</title>
<link href='reset.css' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Whack-a-mole! <span class="score">0</span></h1>
<p><button onClick="startGame()">Start</button></p>
<div class="game">
<div class="hole hole1">
<div class="mole"></div>
</div>
<div class="hole hole2">
<div class="mole"></div>
</div>
<div class="hole hole3">
<div class="mole"></div>
</div>
<div class="hole hole4">
<div class="mole"></div>
</div>
<div class="hole hole5">
<div class="mole"></div>
</div>
<div class="hole hole6">
<div class="mole"></div>
</div>
</div>
<h2 class="game-status"></h2>
<script src="../js/clobber.js"></script>
</body>
</html>
html {
box-sizing: border-box;
font-size: 10px;
background: #ffc600;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
padding: 0;
margin:0;
font-family: 'Amatic SC', cursive;
}
h1, h2 {
text-align: center;
font-size: 10rem;
line-height:1;
margin-bottom: 0;
}
h2 {
font-size: 8rem;
}
.score {
background:rgba(255,255,255,0.2);
padding:0 3rem;
line-height:1;
border-radius:1rem;
}
p {
height: 5rem;
text-align: center;
}
button {
margin: 0 auto;
width: 10rem;
font-size: 3rem;
font-family: 'Amatic SC', cursive;
-webkit-appearance: none;
appearance: none;
font-weight: bold;
background:rgba(255,255,255,0.2);
border: 1px solid black;
border-radius: 1rem;
}
.game {
width:600px;
height:400px;
display:flex;
flex-wrap:wrap;
margin:0 auto;
}
.hole {
flex: 1 0 33.33%;
overflow: hidden;
position: relative;
}
.hole:after {
display: block;
background: url(dirt.svg) bottom center no-repeat;
background-size:contain;
content:'';
width: 100%;
height:70px;
position: absolute;
z-index: 2;
bottom:-30px;
}
.mole {
background:url('mole.svg') bottom center no-repeat;
background-size:60%;
position: absolute;
top: 100%;
width: 100%;
height: 100%;
transition:all 0.4s;
}
.hole.up .mole {
top:0;
}
const score = document.querySelector('.score')
const start = document.querySelector('button')
const holes = document.querySelectorAll('.hole')
function holeAnimate() {
let rand = Math.floor(Math.random() * holes.length)
holes[rand].classList.add('up')
setTimeout(function () {
holes[rand].classList.remove('up')
}, 600)
}
function startGame() {
score.innerHTML = 0
start.style.display = 'none'
let timeId = setInterval(holeAnimate, 400)
setTimeout(function () {
clearInterval(timeId)
start.style.display = 'block'
}, 10000)
}
holes.forEach(function (h) {
h.firstElementChild.onclick = hClick
})
function hClick() {
this.parentElement.classList.remove('up')
score.innerHTML++
}
计时器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Countdown Timer</title>
<link href='https://fonts.googleapis.com/css?family=Inconsolata' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="xome-countdown-timer.css">
</head>
<body>
<div class="timer">
<div class="timer__controls">
<button data-time="20" class="timer__button">20s</button>
<button data-time="300" class="timer__button">5分钟</button>
<button data-time="900" class="timer__button"> 15分钟</button>
<button data-time="1200" class="timer__button">20分钟</button>
<button data-time="3600" class="timer__button">1个小时</button>
<input type="text" name="minutes" placeholder="请输入任意分钟">
</div>
<div class="display">
<h1 class="display__time-left"></h1>
<p class="display__end-time"></p>
</div>
</div>
<script src="../js/countdown2.js"></script>
</body>
</html>
@font-face {
font-family: "Inconsolata";
font-style: normal;
font-weight: 400;
font-stretch: 100%;
src: url(QldgNThLqRwH-OJ1UHjlKENVzkWGVkL3GZQmAwLYxYWI2qfdm7Lpp4U8WRL2l2eY.woff2)
format("woff2");
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1,
U+01AF-01B0, U+1EA0-1EF9, U+20AB;
}
@font-face {
font-family: "Inconsolata";
font-style: normal;
font-weight: 400;
font-stretch: 100%;
src: url(QldgNThLqRwH-OJ1UHjlKENVzkWGVkL3GZQmAwLYxYWI2qfdm7Lpp4U8WRP2l2eY.woff2)
format("woff2");
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB,
U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
font-family: "Inconsolata";
font-style: normal;
font-weight: 400;
font-stretch: 100%;
src: url(QldgNThLqRwH-OJ1UHjlKENVzkWGVkL3GZQmAwLYxYWI2qfdm7Lpp4U8WR32lw.woff2)
format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
U+FEFF, U+FFFD;
}
html {
box-sizing: border-box;
font-size: 10px;
background: #8e24aa;
background: linear-gradient(45deg, #42a5f5 0%, #478ed1 50%, #0d47a1 100%);
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
margin: 0;
text-align: center;
font-family: "Inconsolata", monospace;
}
.display__time-left {
font-weight: 100;
font-size: 20rem;
margin: 0;
color: white;
text-shadow: 4px 4px 0 rgba(0, 0, 0, 0.05);
}
.timer {
display: flex;
min-height: 100vh;
flex-direction: column;
}
.timer__controls {
display: flex;
}
.timer__controls > * {
flex: 1;
}
.timer__controls form {
flex: 1;
display: flex;
}
.timer__controls input {
flex: 1;
border: 0;
padding: 2rem;
}
.timer__button {
background: none;
border: 0;
cursor: pointer;
color: white;
font-size: 2rem;
text-transform: uppercase;
background: rgba(0, 0, 0, 0.1);
border-bottom: 3px solid rgba(0, 0, 0, 0.2);
border-right: 1px solid rgba(0, 0, 0, 0.2);
padding: 1rem;
font-family: "Inconsolata", monospace;
}
.timer__button:hover,
.timer__button:focus {
background: rgba(0, 0, 0, 0.2);
outline: 0;
}
.display {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.display__end-time {
font-size: 4rem;
color: white;
}
.display__time-left::before {
content: "倒计时间";
}
.display__end-time::before {
content: "结束时间: ";
}
const timer = document.querySelectorAll('.timer__button')
const left = document.querySelector('.display__time-left')
const end = document.querySelector('.display__end-time')
const minutes = document.querySelector('input')
timer.forEach(function (item) {
item.onclick = function () {
let time = item.dataset.time - 0
setTime(time)
}
})
minutes.onkeydown = function (e) {
if (e.keyCode != 13) {
return
}
let value = this.value.trim()
if (value.length == 0) return
if (isNaN(value) || parseInt(value) != value || value < 0 || value > 60) {
minutes.value = ''
return
}
minutes.value = ''
setTime(value * 60)
}
function setTime(time) {
let m = Math.floor(time / 60)
let s = time % 60
let date = new Date()
let nowH = date.getHours()
let nowM = date.getMinutes()
let nowS = date.getSeconds()
nowM += m
nowS += s
if (nowS > 59) {
nowS -= 60
nowM++
}
if (nowM > 59) {
nowH += Math.floor(nowM / 60)
nowM %= 60
}
if (s < 10) s = '0' + s
let half = 'am'
if (nowH >= 12) {
half = 'pm'
nowH %= 12
}
if (nowM < 10) nowM = '0' + nowM
left.innerText = `${m}:${s}`
end.innerText = `${nowH}:${nowM} ${half}`
go()
}
let timeId
function go() {
timeId && clearInterval(timeId)
timeId = setInterval(function () {
let time = left.innerText.trim().split(':').map(function (item) {
return parseInt(item.trim())
})
time[1]--
if (time[1] < 0) {
time[1] = 59
time[0]--
}
if (time[0] == 0 && time[1] == 0) {
clearInterval(timeId)
}
if (time[0] < 10) time[0] = '0' + time[0]
if (time[1] < 10) time[1] = '0' + time[1]
left.innerText = `${time[0]}:${time[1]}`
}, 10)
}
今日代办
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="./favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
<link rel="stylesheet" href="./_assets/style.1ece50ac.css">
</head>
<body>
<div id="app">
<div class="box">
<h1>待办列表</h1>
<div class="tool">
<input autofocus type="text" placeholder="请输入待办事项">
</div>
<ul></ul>
<section>
<span>0 未完成</span>
<a href="javascript:;">清理 <b>0</b> 已完成</a>
</section>
</div>
</div>
<script src="../js/todo2.js"></script>
</body>
</html>
* {
margin: 0;
padding: 0;
box-sizing: border-box
}
body {
background-color: #ccc
}
ul {
list-style: none
}
li {
padding: 20px;
text-align: left;
font-size: 30px;
border-bottom: 1px dashed #ccc;
display: flex;
justify-content: space-between;
align-items: center
}
li input {
margin-right: 10px
}
li button {
display: none;
padding: 5px
}
li:hover button {
display: inline-block;
cursor: pointer
}
.finished {
text-decoration: line-through
}
h1 {
margin-bottom: 10px
}
.box {
background-color: #fff;
width: 60vw;
padding: 20px 20px 0;
margin: 50px auto
}
.box .tool input {
width: 100%;
height: 50px;
text-indent: 20px;
font-size: 20px;
font-style: italic;
color: #666;
font-weight: 700
}
section {
height: 50px;
display: flex;
justify-content: space-between;
align-items: center
}
a {
text-decoration-color: #666;
color: inherit
}```
const input = document.querySelector('#app input')
const undo = document.querySelector('#app span')
const clear = document.querySelector('#app b')
input.onkeydown = function (e) {
if (e.keyCode != 13) return
let value = this.value.trim()
this.value = ''
if (value.length === 0) return
const obj = local('undoList')
if (checkLocal(obj, value)) return
obj.push({
checked: false,
value: value,
finished: false
})
local('undoList', obj)
show()
}
document.querySelector('#app ul').onclick = function (e) {
const obj = local('undoList')
if (e.target.nodeName === 'INPUT') {
let index = e.target.parentNode.parentNode.dataset.index
obj[index].checked = !obj[index].checked
obj[index].finished = obj[index].checked ? 'finished' : 'false'
local('undoList', obj)
show()
return
}
if (e.target.nodeName === 'BUTTON') {
let index = e.target.parentNode.dataset.index
obj.splice(index, 1)
local('undoList', obj)
show()
return
}
}
clear.parentElement.onclick = function () {
const obj = local('undoList')
for (let i = 0; i < obj.length; i++) {
if (obj[i].checked) {
obj.splice(i, 1)
i--
}
}
local('undoList', obj)
show()
}
function show() {
const obj = local('undoList')
let str = ''
let undoCount = obj.length
for (let i in obj) {
let checked = ''
if (obj[i].checked) {
checked = 'checked'
undoCount--
}
str += `
<li data-index="${i}">
<div>
<input type="checkbox" ${checked}>
<span class="${obj[i].finished}">${obj[i].value}</span>
</div>
<button>X</button>
</li>
`
}
document.querySelector('#app ul').innerHTML = str
undo.innerText = `${undoCount} 未完成`
clear.innerText = obj.length - undoCount
}
show()
function local(name, value) {
if (name == undefined) return false
let obj = localStorage.getItem(name)
if (obj == null) obj = []
else obj = JSON.parse(obj)
if (value == undefined) return obj
localStorage.setItem(name, JSON.stringify(value))
}
function checkLocal(obj, value) {
for (let i in obj) {
if (obj[i].value == value) return true
}
return false
}```