Friday, February 25, 2011

What Colour Shirt To Wear With Light Grey Suit

Move Rammlied Colombia

With one simple sentence of jQuery we can animate the position of the background image , in the following example we have a div with a background image.
#left
        {
            width:250px;
            height:500px;
            background-image:url(Images/test.png);
            background-position:0px;
            background-repeat:no-repeat;
            float:left;
            overflow:hidden;
            z-index:-1;
        }
<div id="left"></div>
The jQuery instruction:

$("#left").animate({ backgroundPosition: "-500px" }, 700);
We just put in the animate the property backgroundPosition and the new position, after defining the speed of the animation.

0 comments:

Post a Comment