Сообщение от Teamur
|
ВИДИМ процесс выделения (синяя область)
|
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style>
body {
display: flex;
margin: 0;
height: 100vh;
background: #56bddc;
}
#box {
display: flex;
margin: auto;
box-shadow: 0 0 5px hsla(0, 0%, 0%, .25);
}
.el {
width: 60px;
line-height: 60px;
font-family: consolas;
font-size: 30px;
text-align: center;
cursor: pointer;
background: #fff;
-webkit-user-select: none;
user-select: none;
-moz-user-select: none;
}
.el:hover { background: #fece9a; }
.mark { background: #fece9a; }
.blue, .blue:hover{
background: #0000FF;
}
</style>
<script>
window.addEventListener("DOMContentLoaded", function() {
function d(b, c, d) {
[].forEach.call(a, function(e, a) {
(a >= c && a <= d || void 0 === c) && e.classList[void 0 === c ? "remove" : "add"](b)
})
}
var a = document.querySelectorAll(".el"),
b = void 0;
[].forEach.call(a, function(a, c) {
a.addEventListener("mouseover", function() {
if (void 0 !== b) {
var a = Math.min(c, b),
e = Math.max(c, b);
d("blue");
d("blue", a, e)
}
});
a.addEventListener("click", function() {
if (void 0 === b) b = c, d("mark"), d("blue", b, b);
else {
var a = Math.min(c, b),
e = Math.max(c, b);
b = void 0;
d("blue");
d("mark", a, e)
}
})
})
});
</script>
</head>
<body>
<div id='box'>
<div class='el'>1</div>
<div class='el'>2</div>
<div class='el'>3</div>
<div class='el'>4</div>
<div class='el'>5</div>
<div class='el'>6</div>
<div class='el'>7</div>
<div class='el'>8</div>
<div class='el'>9</div>
<div class='el'>X</div>
</div>
</body>
</html>