<?php
/*
调用示例:
$obj = new scroll_bar_class(200,true); //200为进度条的宽度,true为是否显示百分比
$num = 3000;
for($i = 0; $i <= $num; $i++){
$obj->scroll_bar($i,$num);
}
*/
class scroll_bar_class{
function scroll_bar_class( $width = 100,$list_percent = TRUE){
$this->percent = 1;
$this->width = $width;
$this->list_percent = $list_percent;
$create = true;
if( $create ){
$this->create();
$create = false;
}
}
function create(){
if ( $this->list_percent ) $scroll_percent_html = '<td id="scroll_percent" nowrap></td>';
echo '
<table border="0" cellpadding="0" cellspacing="2" style="font-size:12px; margin:0; padding:0px;">
<tr>
<td nowrap>进度条:</td>
<td width="'.$this->width.'" style="background-repeat: repeat-x;background-color:#ECFFEC; border:1px #060 solid;" >
<div id="scroll_img" style="background-color:#060; width:1px; height:12px; line-height:12px; margin:0; padding:0px;"></div>
</td>
'.$scroll_percent_html.'
</tr>
</table>
';
}
function scroll_bar($cur_amount,$max_amount){
$this->percent = round(($cur_amount / $max_amount) * 100);
echo('<script>document.getElementById("scroll_img").style.width = ' . ($this->percent / 100) * $this->width . ';</script>');
if ( $this->list_percent ) echo('<script>document.getElementById("scroll_percent").innerHTML=" '.$this->percent.'%";</script>');
}
}
?>
/*
调用示例:
$obj = new scroll_bar_class(200,true); //200为进度条的宽度,true为是否显示百分比
$num = 3000;
for($i = 0; $i <= $num; $i++){
$obj->scroll_bar($i,$num);
}
*/
class scroll_bar_class{
function scroll_bar_class( $width = 100,$list_percent = TRUE){
$this->percent = 1;
$this->width = $width;
$this->list_percent = $list_percent;
$create = true;
if( $create ){
$this->create();
$create = false;
}
}
function create(){
if ( $this->list_percent ) $scroll_percent_html = '<td id="scroll_percent" nowrap></td>';
echo '
<table border="0" cellpadding="0" cellspacing="2" style="font-size:12px; margin:0; padding:0px;">
<tr>
<td nowrap>进度条:</td>
<td width="'.$this->width.'" style="background-repeat: repeat-x;background-color:#ECFFEC; border:1px #060 solid;" >
<div id="scroll_img" style="background-color:#060; width:1px; height:12px; line-height:12px; margin:0; padding:0px;"></div>
</td>
'.$scroll_percent_html.'
</tr>
</table>
';
}
function scroll_bar($cur_amount,$max_amount){
$this->percent = round(($cur_amount / $max_amount) * 100);
echo('<script>document.getElementById("scroll_img").style.width = ' . ($this->percent / 100) * $this->width . ';</script>');
if ( $this->list_percent ) echo('<script>document.getElementById("scroll_percent").innerHTML=" '.$this->percent.'%";</script>');
}
}
?>
文章来源:桂林唯创网络

