-1

So I have this code below.

<?php

$i = 1;

while($i <= 1000) {
 echo "Number : $i <br />";
 $i++;
}

?>

I want to add some animation while php creating these array one after another, it's like appearing text animation. Is there any way to do that?

Thanks in advance. Any help will be much appreciated.

M Ansyori
  • 429
  • 6
  • 21
  • 4
    The effect you're trying to achieve is not clear, however I can say that there's no way to create an animation in PHP as it runs on the server, long before the DOM exists. You would be best to do this client-side in JS. – Rory McCrossan Aug 11 '16 at 08:11
  • erm, this will not work as you are expecting - php runs at the server so javascript would be a better option – Professor Abronsius Aug 11 '16 at 08:12
  • See comment above. What you need is to run animation client side using javascript or even CSS. – A. Wolff Aug 11 '16 at 08:12
  • Well, okay. So any ideas of how the javascript code look like? thanks. – M Ansyori Aug 11 '16 at 08:13

2 Answers2

0

PHP is running on the server, so you cant create an animation using it. You should to use a language which run on the client side, like javascript (or jQuery).

In this post, the user created a Ajax request. While the server is working and the client is waiting for the response, he wanted to show a 'loading spinner': How to show loading spinner in jQuery?

Community
  • 1
  • 1
dimasdmm
  • 318
  • 4
  • 15
0

Could do this with JavaScript jQuery.

$(document).ready(function () {
var i = 1;

var int = setInterval(function () {
    if (i < 1000) {
     var $div = $("<div>Number : "+i+"</div>").hide();
     $(".container").append($div);
     $div.show(500);
      i++;
    } else {
     clearInterval(int);
    }
},1000);

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="container">

</div>
apokryfos
  • 38,771
  • 9
  • 70
  • 114