简体   繁体   English

PHP进度栏-使用CSS3或jQuery向其中添加一些动画

[英]PHP Progress Bar - add some animation to it using CSS3 or jQuery

I implemented the php progress bar on this link: http://w3shaman.com/article/php-progress-bar-script but I would like to add some animation to it. 我在以下链接上实现了php进度栏: http : //w3shaman.com/article/php-progress-bar-script但我想在其中添加一些动画。 I would like the progress bar width to increase smoothly. 我希望进度条的宽度能够平滑增加。 I tried CSS3 (transition effect) but is does not work. 我尝试了CSS3(过渡效果),但不起作用。 Any idea how animation can be added using CSS3 or jQuery ? 知道如何使用CSS3或jQuery添加动画吗?

Here is the code: 这是代码:

<div id="progress" style="width:500px;border:1px solid #ccc; transition: width 1s ease-in-out;"></div>
<div id="information" style="width"></div>
<?php

$total = 15;

for($i=1; $i<=$total; $i++){
  // Calculate the percentation
  $percent = intval($i/$total * 100)."%";

  // Javascript for updating the progress bar and information
  echo '<script language="javascript">
   document.getElementById("progress").innerHTML=\'<div style="width:'.$percent.'; background-color:#ddd; transition: width 1s ease-in-out;">&nbsp</div>\' ;
  document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
  </script>';

  // This is for the buffer achieve the minimum size in order to flush data
  echo str_repeat(' ',1024*64);

  // Send output to browser immediately
  flush();

  // Sleep one second so we can see the delay
  sleep(1);
}

// Tell user that the process is completed
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
?>

Maybe you can use jquery´s animate 也许您可以使用jquery的动画

Jquery Animate API jQuery Animate API

So in: 所以在:

echo '<script language="javascript">
  document.getElementById("progress").innerHTML=\'<div style="width:'.$percent.'; background-color:#ddd; transition: width 1s ease-in-out;">&nbsp</div>\' ;
  document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
</script>';

you can add a call to the animate function to update the width for progress. 您可以将调用添加到动画函数以更新宽度以进行进度。

Example: 例:

//HTML CODE, add the div to be animated inside the progress bar   
<div id="progress" style="width:500px;border:1px solid #ccc; transition: width 1s ease-in-out;">
 <div id="progressStyle" style="width:0%; background-color:#ddd; transition: width 1s ease-in-out;">&nbsp</div>
</div>

//PHP CODE
echo '<script language="javascript">

$( "#progressStyle" ).animate({
 width: '.$percent.'
 }, 500, function() {
 // Animation complete.
 });
</script>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM