这是方法
var bar = function (id,title,data){
//展示的id
this.id = '';
//标题
this.title = '';
//数据
this.data = '';
//宽
this.width = 500;
//背景图片位置
this.bgimg = 'images/plan.gif';
//动画速度
this.speed = 1000;
//投票总数
var num_all = 0;
this.show = function (){
//添加一个table对象
$("#"+this.id).append("
")
$("#"+this.id+" table").append("
"+this.title+" |
")
//计算总数
$(this.data).each(function(i,n){
num_all += parseInt(n[1]);
})
var that = this;
//起始
var s_img = [0,-52,-104,-156,-208];
//中间点起始坐标
var c_img = [-312,-339,-367,-395,-420];
//结束
var e_img = [-26,-78,-130,-182,-234];
var that = this;
var div;
$(this.data).each(function(i,n){
//计算比例
var bili = (n[1]*100/num_all).toFixed(2);
//计算图片长度, *0.96是为了给前后图片留空间
var img = parseFloat(bili)*0.96;
if(img>0)
{
div = "
";
}
else
{
div='';
}
$("#"+that.id+" table").append("
"+n[0]+": | "+div+" | "+n[1]+"("+bili+"%) |
")
})
this.play();
}
this.play = function (){
var that = this;
$("#"+this.id+" div").each(function(i,n){
if($(n).attr('fag'))
{
$(n).animate( { width: $(n).attr('fag')+'%'}, that.speed )
}
})
}
}
调用