createSpeed.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * 创建进度条 组件
  3. */
  4. function CreateSpeed(option){
  5. this.option = option;
  6. this.isFirstLoad = true;
  7. this.init();
  8. }
  9. CreateSpeed.prototype = {
  10. init:function () {
  11. this.createSpeed();
  12. },
  13. createSpeed:function () {
  14. var _view_ = this;
  15. var html = '';
  16. html += '<div id="'+_view_.option.id+'" class="speed-container">';
  17. html += '<div class="speed-title">';
  18. html += '<span><img src="'+_view_.option.icon+'"></span><span>'+_view_.option.title+'</span><span><img src="icon/xjt.png"></span>';
  19. html += '</div>';
  20. html += '<div class="speed-content">';
  21. html += '<ul>';
  22. html += '<ul>';
  23. html += '</div>';
  24. html += '</div>';
  25. $("#"+_view_.option.id).append(html);
  26. },
  27. setData:function (series) {
  28. var _view_ = this;
  29. function toPoint(point){
  30. var str=Number(point*100).toFixed(1);
  31. str+="%";
  32. return str;
  33. }
  34. var html = '';
  35. series.forEach(function (item,index) {
  36. html += '<li><span>'+item["name"]+'</span><span class="speed-line"><span id="'+_view_.option.id+index+'" class="speed-num" style="background-color: '+item["color"]+'"></span><span class="numText">'+item["data"]+'</span></span></li>';
  37. });
  38. $("#"+_view_.option.id + " ul").html(html);
  39. //动画效果加载数据
  40. if(_view_.isFirstLoad){
  41. series.forEach(function (item,index) {
  42. var dataNum = null;
  43. if(_view_.option.max === null){
  44. dataNum = item["data"];
  45. }else{
  46. dataNum = toPoint(item["data"]/_view_.option.max);
  47. }
  48. $("#"+_view_.option.id+index).animate({
  49. width:dataNum
  50. },2000);
  51. });
  52. _view_.isFirstLoad = false;
  53. }else{
  54. series.forEach(function (item,index) {
  55. var dataNum = null;
  56. if(_view_.option.max === null){
  57. dataNum = item["data"];
  58. }else{
  59. dataNum = toPoint(item["data"]/_view_.option.max);
  60. }
  61. $("#"+_view_.option.id+index).width({
  62. width:dataNum
  63. })
  64. });
  65. }
  66. }
  67. };