Skip to content

Instantly share code, notes, and snippets.

@glauberramos
Last active December 15, 2015 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glauberramos/5230477 to your computer and use it in GitHub Desktop.
Save glauberramos/5230477 to your computer and use it in GitHub Desktop.
Gist to change background color based on mouse position
$('body').mousemove(function(event) {
var width = $('body').width(),
height = $('body').height(),
axisX = event.pageX,
axisY = event.pageY;
var hue = Math.floor(axisX / width * 360),
saturation = Math.floor(axisY / height * 100),
lightness = Math.floor(axisY / height * 100);
$('#header').css('background', 'hsl(' + hue + ',' + saturation + '%, ' + lightness + '%)');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment