Created
May 11, 2015 20:37
-
-
Save egstad/33696f342c2d7c6399b2 to your computer and use it in GitHub Desktop.
Changing background color based on cursor position
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// background color change according to cursor position | |
$(document).mousemove(function (e) { | |
var $width = ($(document).width()) / 255; | |
var $height = ($(document).height()) / 255; | |
var $pageX = parseInt(e.pageX / $width, 10); | |
var $pageY = parseInt(e.pageY / $height, 10); | |
// rgba($a-$b-$c); | |
var $a = $pageX, | |
$b = ($pageY - 255) * (-1), | |
$c = 0; | |
// if cursor is in bottom left, adjust $c accordingly | |
if ($pageX <= $pageY) { | |
$c = $pageY - $pageX; | |
} | |
// change element to whatever you need to target | |
$(element).css('background-color', 'rgb('+$a+','+$b+','+$c+')'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment