I created two versions of the pixel maker, one with vanilla JS and the other with jQuery. When you try to draw a grid, if you move too fast, the cell is dragged, and after you release the mouse pointer, it displays the no symbol (a circle with a line through it) and retains color (which does not happen otherwise). The only way to get him to stop painting at this point is to click on the cell. What code can be added, if any, to prevent this default browser behavior for each version?
I'm not sure if this is what needs to be changed, but here are my functions for dragging and dropping colors:
jQuery (view CodePen for full code):
function dragColor() {
$(pixelCanvas).on('mousedown', 'td', function() {
mousedown = true;
});
$(document).mouseup(function() {
mousedown = false;
});
$(pixelCanvas).on('mouseover', 'td', function() {
if (mousedown) {
$(this).css('background-color', color);
}
});
}
Vanilla JS ( ) CodePen:
let down = false;
pixelCanvas.addEventListener('mousedown', function(e) {
down = true;
pixelCanvas.addEventListener('mouseup', function() {
down = false;
});
pixelCanvas.addEventListener('mouseleave', function() {
down = false;
});
pixelCanvas.addEventListener('mouseover', function(e) {
const color = document.querySelector('.color-picker').value;
if (down) {
if (e.target.tagName === 'TD') {
e.target.style.backgroundColor = color;
}
}
});
});