I do Etch-a-Sketch.
It is one of the functions. It work normally on computer with mouse. But don’t work on touch screens (phone).
I need both functionality: for computer mouse and for touch screens.
mouseSquares.forEach(gridSquares => {
gridSquares.addEventListener('mouseover', () => {
if (mouseHoveringColor === "yellow") {
gridSquares.style.backgroundColor = mouseBackgroundColor;
} else if (mouseHoveringColor === "randomize") {
gridSquares.style.backgroundColor = mouseBackgroundColor;
} else {
let r = Math.floor(Math.random() * 256);
let g = Math.floor(Math.random() * 256);
let b = Math.floor(Math.random() * 256);
gridSquares.style.backgroundColor = `rgb(${r}, ${g}, ${b})`;
}
});
gridSquares.addEventListener('click', () => {
gridSquares.style.backgroundColor = SQUARESBACKGROUNDCOLOR;
});
});
I tried add events touchmove
and touchcancel
– but it doesn’t work too.
I need both functionality: for computer mouse and for touch screens.
New contributor
OlKlym is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1