Created
July 7, 2019 15:16
-
-
Save cemerson/1eccc45e93d9d2ae43c3ba0056c36d3e to your computer and use it in GitHub Desktop.
jQuery Animate Background Postion (CSS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/questions/12340130/jquery-animate-background-image-on-y-axis | |
$.fn.animateBG = function(x, y, speed) { | |
var pos = this.css('background-position').split(' '); | |
this.x = pos[0].split('px')[0] || 0; | |
this.y = pos[1].split('px')[0] || 0; | |
$.Animation( this, { | |
x: x, | |
y: y | |
}, { | |
duration: speed | |
}).progress(function(e) { | |
this.css('background-position', e.tweens[0].now+'px '+e.tweens[1].now+'px'); | |
}); | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment