I want to change the color of the background based on mouse position

jquery

Solution

Probably because you're getting fractions back.

Try:

var $pageX = parseInt(e.pageX / $width,10);
var $pageY = parseInt(e.pageY / $height,10);

jsFiddle example

Problem

Here is my code: ``` $(document).mousemove(function(e){ var $width = ($(document).width())/255; var $height = ($(document).height())/255; var $pageX = e.pageX / $width; var $pageY = e.pageY / $height; $("body").css("background-color", "rgb("+$pageX+","+$pageY+","+$pageX+")"); }); ``` This kind of works, except the mousemove seems to not refresh every time it is moved. It seems to lag, is there some setting that I am missing? The page x and page y are multiplied by the documents relative size to 255, so that the entire spectrum is being used. Thanks.

Original source