I'm trying to create a small, square div that follows the mouse cursor, but I want it to snap to a 3x3 pixel grid.
Here is what I have so far:
$(document).mousemove(function(e) {
window.x = e.pageX;
window.y = e.pageY;
if(window.x % 9 === 0 ){
$("div").css("left",window.x);
$("div").css("top",window.y);
}
});
However, the snapping isn't quite right and the movement is slow. Additionally, I need the pixel grid to align with a parent div container rather than the browser window size.