Skip to content

Instantly share code, notes, and snippets.

@katafrakt
Last active December 12, 2015 01:38
Show Gist options
  • Save katafrakt/4692236 to your computer and use it in GitHub Desktop.
Save katafrakt/4692236 to your computer and use it in GitHub Desktop.
/**
* jQuery background position plugin
* adapted to width recalculation
* original by Alexander Farkas
*/
(function($) {
Tween = jQuery.Tween;
jQuery.Tween.prototype.run = function( percent ) {
var eased,
hooks = Tween.propHooks[ this.prop ];
if ( this.options.duration ) {
this.pos = eased = jQuery.easing[ this.easing ](
percent, this.options.duration * percent, 0, 1, this.options.duration
);
} else {
this.pos = eased = percent;
}
positionProps = ['width', 'height', 'left', 'right', 'top', 'bottom', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom',
'marginTop', 'marginLeft', 'marginBottom', 'marginRight'];
if (jQuery.inArray(this.prop, positionProps) != -1)
this.now = Math.round(( this.end - this.start ) * eased + this.start);
else
this.now = ( this.end - this.start ) * eased + this.start;
if ( this.options.step ) {
this.options.step.call( this.elem, this.now, this );
}
if ( hooks && hooks.set ) {
hooks.set( this );
} else {
Tween.propHooks._default.set( this );
}
return this;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment