I am currently working on implementing a parallax effect, which is mostly successful. However, I have encountered a minor issue. Instead of the parallax effect being relative to the element's current position, it abruptly jumps to position 0. How can I adjust the code to make the parallax effect relative to its current position?
Below is the JavaScript code I am using:
$("#caveConfron").mousemove(function(e){
var x = e.pageX - this.offsetLeft;
var alreadyY = $("#caveConfron").css("backgroundPositionY");
$("#caveConfron").css({"backgroundPosition":-(x/85)+"% 0%"});
});
Here is the CSS code related to the element:
#caveConfron{
width:242px;
height:344px;
border:5px solid black;
background:url('../img/caveConfrontBg.jpg') no-repeat center top;
position:relative;
}
You can see an example of the issue here: http://jsfiddle.net/gNCjS/