S
S
Sedbol2020-05-08 02:07:33
JavaScript
Sedbol, 2020-05-08 02:07:33

How to highlight click on an element while holding down the mouse button?

How can I make it click on an element when the mouse button is held down? It is necessary to make it so that when you click on an element, it is painted, and if you move the mouse to another without releasing the button, a click is made on it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-05-08
@Sedbol

.active {
  background: black;
  color: white;
}

const handler = e =>
  e.buttons === 1 &&
  e.target.classList.contains('but') &&
  e.target.classList.add('active');

document.addEventListener('click', handler);
document.addEventListener('mousemove', handler);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question