JSFiddle - React, Tailwind, and code Playground
HTML
<div id="wrapper">
<div id="block"></div>
</div>
CSS
#wrapper {
width: 400px;
height: 300px;
background: url("https://dl.dropbox.com/u/2787908/background.png") no-repeat 0 0;
position: relative;
margin: 15px;
}
#block {
width: 400px;
height: 100px;
background: #99f;
position: absolute;
top: 100px;
}
JavaScript
$(document).ready(function(){
$("#wrapper").animate({ backgroundPosition:"(0 -100px)" }, 20000, "linear");
$("#block").animate({ top: 0 }, 20000, "linear");
});
/* background position animation plugin */
(function($) {
if(!document.defaultView || !document.defaultView.getComputedStyle){
var oldCurCSS = jQuery.curCSS;
jQuery.curCSS = function(elem, name, force){
if(name === 'background-position'){
name = 'backgroundPosition';
}
if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
return oldCurCSS.apply(this, arguments);
}
var style = elem.style;
if ( !force && style && style[ name ] ){
return style[ name ];
}
return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
};
}
var oldAnim = $.fn.animate;
$.fn.animate = function(prop){
if('background-position' in prop){
prop.backgroundPosition = prop['background-position'];
delete prop['background-position'];
}
if('backgroundPosition' in prop){
prop.backgroundPosition = '('+ prop.backgroundPosition + ')';
}
return oldAnim.apply(this, arguments);
};
function toArray(strg){
strg = strg.replace(/left|top/g,'0px');
strg = strg.replace(/right|bottom/g,'100%');
strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
}
$.fx.step.backgroundPosition = function(fx) {
if (!fx.bgPosReady) {
var start = $.curCSS(fx.elem,'backgroundPosition');
if(!start){//FF2 no inline-style fallback
start = '0px 0px';
}
...