Reputation: 296
I'm trying to set up a very simple mousemove event, which applies filter: (XXdeg) CSS to my background div based on mouse position. I've done this successfully in the past with background-color but it doesn't seem to be working for the filter property.
Here's what I have:
$(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);
$(".bg").css("filter", "hue-rotate(" + (255 - $pageX) + ")");
});
Would very much appreciate if someone could point out where I might be going wrong with this. Page with this code applied is here: http://www.joe-goddard.com
Thanks!
Upvotes: 2
Views: 516
Reputation: 1389
I just tried that code, the only thing you're missing is the "deg" unit after the filter value.
var $document = $(document);
$document.mousemove(function(e) {
var width = $document.width() / 255;
var pageX = e.pageX / width;
var value = 255 - pageX;
$(".bg").css("filter", "hue-rotate(" + value + "deg)");
});
Upvotes: 3
Reputation: 8210
You have to specify what unit will be 255, in this case, deg
(degree).
$(".bg").css("filter", "hue-rotate(" + (255 - $pageX) + "deg)");
Upvotes: 3