Reputation: 1007
I'm trying to animate a static background, but my issue was since I do not have such a big background image and I do not want user to see the outer part of my background.
To encounter this issue. I'm trying to reverse my event.pageX values when I reach 1280 and above, but I just cant figure out how to reverse the animation....
$("header .headerInnerWrapper").mousemove(function(event) {
var xPos = event.pageX;
console.log(xPos);
if(xPos>=1280){//reverse the number
//will be 1279,1278, 1277.......
}
bg.css('backgroundPosition', [xPos] + "px");
});
Upvotes: 2
Views: 542
Reputation: 34180
$("header .headerInnerWrapper").mousemove(function(event) {
var xPos = event.pageX;
console.log(xPos);
if(xPos>=1280){
xPos = 2560 - xPos; // that would be 1280 - (xpos -1280);
}
bg.css('backgroundPosition', [xPos] + "px");
});
or to work with all values:
$("header .headerInnerWrapper").mousemove(function(event) {
var xPos = event.pageX;
console.log(xPos);
if(xPos>=1280){
xPos = Math.ceil(xPos/1280)*1280 - xPos;
}
bg.css('backgroundPosition', [xPos] + "px");
});
Upvotes: 1