Показать сообщение отдельно
  #7 (permalink)  
Старый 19.03.2018, 15:47
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,135

выделение диапазона по двум кликам
Янковиц,

<!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() {
  [].forEach.call(document.querySelectorAll(".box"), function(item) {
    var temp;
    item.addEventListener("click", function(event) {
      var el = item.querySelectorAll(".el");
      target = event.target;
      var index = [].indexOf.call(el, target);
      if (index !== -1) {
        [].forEach.call(el, function(el) {
          el.classList.remove("blue");
        });
        if (temp == index) {
          temp = void 0;
        } else {
          if (void 0 === temp) {
            target.classList.add("blue");
            temp = index;
          } else {
            var min = Math.min(index, temp), max = Math.max(index, temp);
            el = [].slice.call(el, min, ++max);
            [].forEach.call(el, function(el) {
              el.classList.add("blue");
            });
            temp = void 0;
          }
        }
      }
    });
    item.addEventListener("mouseover", function(event) {
      var el = item.querySelectorAll(".el");
      target = event.target;
      var index = [].indexOf.call(el, target);
      if (index !== -1) {
        if (void 0 !== temp) {
          [].forEach.call(el, function(el) {
            el.classList.remove("blue");
          });
          var min = Math.min(index, temp), max = Math.max(index, temp);
          el = [].slice.call(el, min, ++max);
          [].forEach.call(el, function(el) {
            el.classList.add("blue");
          });
        }
      }
    });
    item.addEventListener("mouseleave", function(event) {
      var el = item.querySelectorAll(".el");
      if (temp) {
        [].forEach.call(el, function(el) {
          el.classList.remove("blue");
        });
        el[temp].classList.add("blue");
        temp = void 0;
      }
    });
  });
});
  </script>
</head>

<body>
<div class='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>
Ответить с цитированием