PHP-如何用PHP生成一个渐变的进度条?

需求定制 需求定制 主题:1050 回复:2283

PHP-如何用PHP生成一个渐变的进度条?

清晨说ぺ晚安 发布于 2017-08-06 字数 191 浏览 1044 回复 3

要求:随机输入起点色和终点色

如何用PHP生成一个如下图一样平滑的颜色渐变进度条?

请输入图片描述

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

支持 Markdown 语法,需要帮助?

评论(3

偏爱自由 2017-10-09 3 楼

可能需要调整一下你服务器的配置,让页面能实时输出

function create_progress() {
echo "
<style>

text {

position: absolute;
top: 100px;
left: 50%;
margin: 0px 0px 0px -150px;
font-size: 18px;
text-align: center;
width: 300px;
}

barbox_a {

position: absolute;
top: 130px;
left: 50%;
margin: 0px 0px 0px -160px;
width: 304px;
height: 24px;
background-color: black;
}
.per {
position: absolute;
top: 130px;
font-size: 18px;
left: 50%;
margin: 1px 0px 0px 150px;
background-color: #FFFFFF;
}

.bar {
position: absolute;
top: 132px;
left: 50%;
margin: 0px 0px 0px -158px;
width: 0px;
height: 20px;
background-color: #0099FF;
}

.blank {
background-color: white;
width: 300px;
}
</style>
";
echo "
<div id='text'>Script Progress</div>
<div id='barbox_a'></div>
<div class='bar blank'></div>
<div class='per'>0%</div>
";
flush();
}
function update_progress($percent) {
echo "<div class='per'>{$percent}
%</div>n";

echo "<div class='bar' style='width: ",
$percent * 3, "px'></div>n";

flush();
}

create_progress();
usleep(350000);
update_progress(7);
usleep(1550000);
update_progress(28);
usleep(1000000);
update_progress(48);
usleep(1000000);
update_progress(68);
usleep(150000);
update_progress(71);
usleep(150000);
update_progress(74);
usleep(150000);
update_progress(77);
usleep(1150000);
update_progress(100);

JS实现应该会好很多,推荐用Jquery的插件

想挽留 2017-09-04 1 楼

用js就可以实现

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<title>Js技术生成彩色渐变条</title>
<script language="JavaScript1.2">
<!--

if (document.all){
one=new Array();
two=new Array();
var a=10;var b=11;var c=12;var d=13;var e=14;var f=15;
var width = 250;
var height = 20;
var gap = 5;
var direction = 0;
one[0]=f;
one[1]=f;
one[2]=0;
two[0]=0;
two[1]=c;
two[2]=0;

if(direction==0) var num = width / gap;
if(direction==1) var num = height / gap;
color2=new Array();
color1=new Array();
diff=new Array();
for(i=0;i<3;i++) {
diff[i] = two[i] - one[i];
diff[i] = diff[i] / num;
}
for(i=0;i<3;i++){
color1[i] = Math.round(diff[i] Math.pow(10, 0));
if(color1[i] > diff[i])color1[i] = color1[i] - 1;
color2[i] = diff[i] - color1[i];
color2[i] = color2[i]
15;
color2[i] = Math.round(color2[i] * Math.pow(10, 0));
}
x=new Array();
two[0]=0;
two[1]=0;
two[2]=0;
document.write('<table border="0" cellpadding="0" cellspacing="0" width="'+width+'" height="'+height+'">');
if(direction==0) document.write('<tr>');
for(i=0;i<=num;i++) {
if(direction==1) document.write('<tr>');
document.write('<td bgcolor="#');
for(j=0;j<3;j++) {
if(one[j]==a)document.write("a");
if(one[j]==b)document.write("b");
if(one[j]==c)document.write("c");
if(one[j]==d)document.write("d");
if(one[j]==e)document.write("e");
if(one[j]==f)document.write("f");
if(one[j]<10)document.write(one[j]);
if(two[j]==a)document.write("a");
if(two[j]==b)document.write("b");
if(two[j]==c)document.write("c");
if(two[j]==d)document.write("d");
if(two[j]==e)document.write("e");
if(two[j]==f)document.write("f");
if(two[j]<10)document.write(two[j]);
one[j] = one[j] + color1[j];
two[j] = two[j] + color2[j];
if(two[j]>15) {
two[j] = two[j] - 15;
one[j]++;
}
}
if(direction==0) document.write('" width="'+gap+'" height="'+height+'">&nbsp;</td>');
if(direction==1) document.write('" width="'+width+'" height="'+gap+'">&nbsp;</td></tr>');
}
document.write('</table>');
}
//-->
</script>
</head>
<body>
</body>
</html>

参考地址:http://www.codefans.net/jscss/code/3351.shtml