I\'m trying to create a slight parallax effect (I\'m not sure if it really constitutes parallax but it\'s a similar idea). Where there are four layers which all move around at a
How about using jQuery.offSet() instead? You might want to adjust the math/values, but I think it should set you in the right direction.
$(document).ready(function () {
$('#layer-one').mousemove(function (e) {
parallax(e, this, 1);
parallax(e, document.getElementById('layer-two'), 2);
parallax(e, document.getElementById('layer-three'), 3);
});
});
function parallax(e, target, layer) {
var layer_coeff = 10 / layer;
var x = ($(window).width() - target.offsetWidth) / 2 - (e.pageX - ($(window).width() / 2)) / layer_coeff;
var y = ($(window).height() - target.offsetHeight) / 2 - (e.pageY - ($(window).height() / 2)) / layer_coeff;
$(target).offset({ top: y ,left : x });
};
JSFiddle: http://jsfiddle.net/X7UwG/854/