Why not do it like this:
var currentColor; var isMouseDown = false; $('.colors').click(function() { $(this).fadeTo("fast", 0.40); currentColor = $(this).css("background-color"); $('.colors').not(this).fadeTo("fast", 1); }); $('td').mousedown(function() { isMouseDown = true; }); $('td').mouseup(function() { isMouseDown = false; }); $('td').hover(function() { if (isMouseDown) { $(this).css("background-color", currentColor); } }); $("#reset").click(function() { $("td").css("background-color", "white") });
So, I think the correct implementation would be to capture the mouseup
/ mousedown
events, hold the state in the isMouseDown
variable isMouseDown
and check this variable in the hover()
function.
source share