master
2022-03-28 b0ee3100f52959ca40b604ec12d7b32ce55c61d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var btnbar = {
  canMove: true,
  picDiv: null,
  positionl: 0,
  picwidth: 170,
  maxWidth: NaN,
  fundata: {},
  init: function (arrdata) {
    if (!document.getElementById("btnbar")) {
      $("body").prepend(
        '<div class="btnbar"> <div class="btnbar_panel"> <div class="btnbar_left"></div> <div class="btnbar_items_panel"><div class="btnbar_items_panel_scroll">  </div></div><div class="btnbar_right"></div>   </div></div>'
      );
    }
 
    var inhtml = "";
    for (var i = 0; i < arrdata.length; i++) {
      var item = arrdata[i];
      inhtml += '<div class="btnbar_item">' + item.name + "</div>";
      this.fundata[item.name] = item;
    }
    $(".btnbar_items_panel_scroll").html(inhtml);
 
    this.picDiv = $(".btnbar_items_panel_scroll");
    this.maxWidth = 800 - arrdata.length * (this.picwidth + 5);
 
    $(".btnbar_item").bind("click", function () {
      $(this).addClass("btnbar_item_select").siblings().removeClass("btnbar_item_select");
 
      var _text = $(this).text();
      btnbar.fundata[_text].click();
    });
 
    if (this.maxWidth > 0) {
      $(".btnbar_left").hide();
      $(".btnbar_right").hide();
      this.picDiv.animate({ left: this.maxWidth / 2 + "px" });
    } else {
      $(".btnbar_left").bind("click", function () {
        btnbar.moveToLeft();
      });
      $(".btnbar_right").bind("click", function () {
        btnbar.moveToRight();
      });
    }
  },
  //左移
  moveToLeft: function () {
    if (this.positionl >= 0) {
      return;
    }
 
    this.positionl += this.picwidth;
    if (this.positionl >= 0) {
      this.positionl = 0;
    }
    this.picDiv.animate({ left: this.positionl + "px" });
  },
  //右移
  moveToRight: function () {
    if (this.positionl <= this.maxWidth) {
      return;
    }
 
    this.positionl -= this.picwidth;
    if (this.positionl <= this.maxWidth) {
      this.positionl = this.maxWidth;
    }
    this.picDiv.animate({ left: this.positionl + "px" });
  },
  unSelect: function () {
    $(".btnbar_item").each(function () {
      $(this).removeClass("btnbar_item_select");
    });
  },
};