javascript - How to stop animation on background image -
i have animation on background image in website, image moving on left time when image come end start again. problem when image come end (left side) edges visible , want when come left side go right, when come right side..on left again.
var x=0; var y=0; var banner = $("#loading"); banner.css('backgroundposition', x + 'px' + ' ' + y + 'px'); window.setinterval(function(){ banner.css('backgroundposition', x + 'px' + ' ' + y + 'px'); x--; }, 90);
here's example animation:
var x = 0; var fps = 30; var speed = 2; var bannerwidth = 400; var imagesize = 128; setinterval(function() { x += speed; if (x >= bannerwidth-imagesize || x <= 0) { speed *= -1; } $("#banner").css("backgroundposition", x + "px 0"); }, 1000/fps);
#banner { width: 400px; height: 128px; border: 1px solid red; background-image: url("http://icons.iconarchive.com/icons/position-relative/social-1/128/google-icon.png"); background-position: 0 0; background-repeat: no-repeat; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="banner"></div>
i can modify example if provide html & css.
Comments
Post a Comment