开发者

jQuery - Animate & Time interval

<script>
 $(document).ready(function() {

 $.get("database.php", function(data){
  var xp = data + "%";
  $('#exp_bg').animate({
   width: xp
  }, 1500, function() { });
 });

});
</script>

Database.php:

<?php
 $xp = 50;
 $level = 100;

 $xp_percent = $xp * 100 / $level;
 echo $xp_percent;
?>

What i'm trying to do, is that if $xp_percent increases in database.php, then #exp_bg's width will animate into desired width without refresh.

I tried to do that with time interval, which takes data from database.php every speciefed interval of time, but i failed doing that.

Could anyone help m开发者_JS百科e with that?


Your probably going to have to put it inside a setTimeout function like so:

var refreshId = setInterval(function() { 

$.get("database.php", function(data){
  var xp = data + "%";
  $('#exp_bg').animate({
   width: xp
  }, 1500, function() { });
 });


}, 1000);

This would check every second.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜