A jQuery plugin that allows the position of a background image to be animated. If you find this plugin useful please vote for it on the jQuery site.
The current version is 1.0.1 and is available under the GPL and MIT licences. For more detail see the documentation reference page.
You can animate the position of a background image as either
'backgroundPosition' or 'background-position',
providing both the horizontal and vertical offsets.
Simple animation:
$('#simpleButton').click(function() {
$('#simpleBG').css({backgroundPosition: '0px 0px'}).
animate({backgroundPosition: '-200px -150px'});
});
You have several options when specifying the new background position, besides supplying an absolute offset.
By named position:
$('#namedSelect').change(function() {
$('#namedBG').animate({backgroundPosition: $(this).val()});
});
By relative position:
$('#relativeButton').click(function() {
$('#relativeBG').animate({backgroundPosition: $('#relativeSelect').val()});
});
You can still use the standard options of all animations.
Speed:
$('#speedButton').click(function() {
var speed = parseInt($('#speedSelect').val(), 10);
speed = (isNaN(speed) ? $('#speedSelect').val() : speed);
$('#speedBG').animate({backgroundPosition: '+=50% +=50%'}, speed);
});
Easing:
$('#easingButton').click(function() {
$('#easingBG').animate({backgroundPosition: '+=50% +=50%'},
2000, $('#easingSelect').val());
});
Callback:
$('#callbackButton').click(function() {
$('#callbackBG').animate({backgroundPosition: '+=50% +=50%'},
1000, function() { alert('Completed animation'); });
});
This tab highlights examples of this plugin in use "in the wild".
None as yet.
To add another example, please contact me (kbwood{at}iinet.com.au) and provide the plugin name, the URL of your site, its title, and a short description of its purpose and where/how the plugin is used.
Below are examples of how the plugin can be used. For more detail see the documentation reference page.
$(selector).animate({backgroundPosition: '-100px -50px'});
$(selector).animate({'background-position': '+=50% +=25%'});
$(selector).animate({backgroundPosition: 'left center'});
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script><script type="text/javascript" src="jquery.backgroundpos.js"></script>
Alternately, you can use the packed version
jquery.backgroundpos.pack.js (1.7K vs 2.5K), or the minified version
jquery.backgroundpos.min.js (1.6K, 0.8K when zipped).$(selector).animate({backgroundPosition: '-100px -50px'});For more detail see the documentation reference page.
I just wanted to thank you for your wonderful jQuery plugin. I was having problems with IE not working with my animations and your plugin really helped me out.
Contact Keith Wood at kbwood{at}iinet.com.au with comments or suggestions.
| Version | Date | Changes |
|---|---|---|
| 1.0.1 | 28 May 2011 |
|
| 1.0.0 | 13 Nov 2010 |
|