$(document).ready(function() { setTimeout(animateBarometer,1000); $('.temBox span').html('607'); }); function animateBarometer() { var b = $('.barometer'); var v = 607; var t = 270 - ((220 / 600) * v) + 18; var c = 0; if ($('.barometer').css('background-position') == undefined) { c = $('.barometer').css('background-position-y').replace(/px/,"").replace(/\s/gi,""); } else { c = $('.barometer').css('background-position').replace(/50%/,"").replace(/px/,"").replace(/\s/gi,""); } /* // 270px = 50 if (v <= 50 && c == 270) { b.css('background-position','50% 250px'); return; } // 50px = 650 if (v >= 650 && c == 50) { b.css('background-position','50% 50px'); return; } */ if (c == 0) { return; } if (c > t) { b.css('background-position','50% '+(c-2.5)+'px'); setTimeout(animateBarometer,10); } }