第一發部落格不懂的可以私信加評論秒回
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html,
body,
div,
span,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
abbr,
address,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
samp,
small,
strong,
sub,
sup,
var,
b,
i,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section,
summary,
time,
mark,
audio,
video {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body {
line-height: 1;
}
:focus {
outline: 1;
}
article,
aside,
canvas,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section,
summary {
display: block;
}
ul {
list-style: none;
}
blockquote,
q {
quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
content: "";
content: none;
}
a {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
text-decoration: none;
}
ins {
background-color: #ff9;
color: #000;
text-decoration: none;
}
mark {
background-color: #ff9;
color: #000;
font-style: italic;
font-weight: bold;
}
del {
text-decoration: line-through;
}
abbr[title],
dfn[title] {
border-bottom: 1px dotted #000;
cursor: help;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #cccccc;
margin: 1em 0;
padding: 0;
}
input,
select {
vertical-align: middle;
}
.fl {
float: left;
}
.fr {
float: right;
}
html,
body {
height: 100%;
width: 100%;
font-family: "微軟雅黑";
overflow: hidden;
}
input,
textarea {
border: none;
}
#box {
width: 100%;
position: relative;
}
#tab {
width: 100%;
position: absolute;
top: 0;
}
.td {
width: 100%;
height: 120px;
display: flex;
}
.tr {
width: 100%;
height: 120px;
}
</style>
</head>
<body>
<div id="box">
<div id="tab">
</div>
</div>
<script>
//渲染表格
var tab = document.getElementById('tab')
var pin = ``
for (var i = 0; i < 100; i++) {
pin += `<div class="td">`
for (var j = 0; j < 4; j++) {
pin += `<div class="tr"></div>`
}
pin += '</div>'
}
pin += ''
tab.innerHTML = pin
//計算高度
var tr = document.querySelectorAll('.td')
let seeHeight = document.documentElement.clientHeight; //可見區域高度
tab.style = `height:${tr[0].offsetHeight * tr.length}px`
//定位到底部
tab.style.top = seeHeight - (tr[0].offsetHeight * tr.length) + 'px'
//封裝随機顔色
var tr = document.querySelectorAll('.td')
for (let i = 0; i < tr.length; i++) {
var color = parseInt(Math.random() * 4)
for (var j = 0; j < tr[i].children.length; j++) {
j == color ? tr[i].children[j].style.background = '#000' : tr[i].children[j].style.background = '#fff'
}
}
//封裝檢測未按表格
function detection(calculate, trLength, miscalculation) {
var calculateTop = seeHeight - (tr[0].offsetHeight * tr.length)
var detectionTr = ''
var correct = setInterval(() => {
calculate++
calculateTop++
tab.style.top = calculateTop + 'px'
if (calculate >= tr[0].offsetHeight) {
for (let i = 0; i < tr[trLength].children.length; i++) {
if (tr[trLength].children[i].style.background == 'rgb(0, 0, 0)') {
detectionTr = true
}
}
if (detectionTr) {
var tabTop = parseInt(tab.style.top)
var mistake = setInterval(() => {
miscalculation--
tab.style.top = tabTop + miscalculation + 'px'
if (miscalculation <= -tr[0].offsetHeight) {
clearInterval(mistake)
}
}, 10)
}
calculate = 0
trLength--
}
}, 10)
}
//點選事間
var con = 0
var trLlenjth = tr.length - 1
for (let i = tr.length - 1; i >= 0; i--) {
for (let v = 0; v < tr[i].children.length; v++) {
tr[i].children[v].onclick = function () {
if (tr.length - 1 == i) {
detection(0, tr.length - 1, 0)
tr[i].children[v].style.background == '#fff'
}
if (tr[i].children[v].style.background == 'rgb(0, 0, 0)' && trLlenjth == i) {
tr[i].children[v].style.background = '#fff'
trLlenjth--
con++
}
if (con == tr.length) {
detection = null
console.log(con)
}
}
}
}
</script>
</body>
</html>
## 标題啊是大