code

drag-to-paint boxes

a row of small boxes turns green as the pointer crosses them with the mouse button held down.

html

<body>
  <div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
  </div>
</body>

css

div {
  width: 500px;
  height: 50px;
}

div div {
  width: 50px;
  height: 50px;
  outline: 1px solid;
  float: left;
}

javascript

var box;
var boxArray;
boxArray = [];

box = document.getElementsByClassName("box");
for (var i = 0; i < box.length; i++)
  (function (i) {
    box[i].onmousemove = function (e) {
      if (e.buttons == 1) box[i].style.backgroundColor = "green";
    };
  })(i);

this demo preserves the compiled output and may depend on external libraries or services that are no longer available.

original jsfiddle post