Hi,
I have a parallax script that should get the images from the document and move them according to mouse movement.
It doesn’t work.
Can you know what is the problem?
<script>
window.onload = function() {
var c1left = document.getElementById('l2').offsetLeft,
c1top = document.getElementById('l2').offsetTop,
c2left = document.getElementById('l3').offsetLeft,
c2top = document.getElementById('l3').offsetTop,
parallaxBox.onmousemove = function(event) {
event = event || window.event;
var x = event.clientX - parallaxBox.offsetLeft,
y = event.clientY - parallaxBox.offsetTop;
mouseParallax('l2', c1left, c1top, x, y, 50);
mouseParallax('l3', c2left, c2top, x, y, 20);
}
}
function mouseParallax(id, left, top, mouseX, mouseY, speed) {
var obj = document.getElementById(id);
var parentObj = obj.parentNode,
containerWidth = parseInt(parentObj.offsetWidth),
containerHeight = parseInt(parentObj.offsetHeight);
obj.style.left = left - (((mouseX - (parseInt(obj.offsetWidth) / 2 + left)) / containerWidth) * speed) + 'px';
obj.style.top = top - (((mouseY - (parseInt(obj.offsetHeight) / 2 + top)) / containerHeight) * speed) + 'px';
}
</script>
Thanks!