jak przesuwać tło w divie, tworząc tylko krótki obrazek tła i powtarzać go w pętli?
Znalazlem taki przyklad, ktory prawie mi odpowiada, ale tutaj tworza długi obrzek tła na szerokość 1000px i animuja tylko 1 raz.
http://robot.anthonycalzadilla.com/
$(document).ready(function(){ $('#ground').css({backgroundPosition: 'left bottom'}); $('#wrapper').css({overflow: "hidden"}); animation(); //setTimeout("animation2()",10000); }); function animation() { $('#ground').animate({backgroundPosition: '(-500px bottom)'}, 1000); animation2(); } function animation2() { $('#ground').animate({backgroundPosition: '(0px bottom)'}, 10000); animation(); }
div {position: relative;} #wrapper { background: #bedfe4 url(sun.png) no-repeat left -30px; border: 5px solid #402309; height: 400px; width:500px; } #ground { background: url(ground-05.png) no-repeat left bottom; height: 400px; width: 1000px; } #branding { background: url(robot-head.png) no-repeat center top; width: 271px; height: 253px; z-index: 4; }
function animation2() { $('#ground').css({backgroundPosition: '(0px bottom)'}); animation(); }
function animation() { $('#ground').animate({backgroundPosition: '(-500px bottom)'}, 10000); animation2(); } function animation2() { $('#ground').css({backgroundPosition: '0px bottom'}); animation(); }
function animation2() { $('#ground').css({backgroundPosition: '0 0'}); animation(); }
$(document).ready(function(){ animation(); setTimeout("animation2", 1000); }); function animation() { $('#ground').animate({backgroundPosition: '(-500px bottom)'}, 1000); } function animation2() { $('#ground').css("backgroundPosition", "0px bottom"); animation(); }
$(document).ready(function(){ animation(); }); function animation() { $('#ground').animate({backgroundPosition: '(-500px bottom)'}, 10000); animation2(); } function animation2() { //$('#ground').animate("background-position", "0 bottom"); //$('#ground').css("background-position", "0px bottom"); $('#ground').animate({backgroundPosition: '(0px bottom)'}); animation(); }
$(document).ready(function(){ animation(); }); function animation() { $('#ground').animate({backgroundPosition: '(-500px bottom)'}, 10000, '', animation2); } function animation2() { $('#ground').css("background-position", "0px bottom"); animation(); }