DivManager.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. (function() {
  2. var ArrayIndexof = function(arr, obj) {
  3. var index = 0;
  4. for(index = 0; index < arr.length; index++) {
  5. if(obj === arr[index]) {
  6. return index;
  7. }
  8. }
  9. return -1;
  10. };
  11. FZ.DivManager = {
  12. m_init : false,
  13. m_parentContainer : null,
  14. m_display_list : null,
  15. offsetLeft : 0,
  16. offsetTop : 0,
  17. init : function() {
  18. if(this.m_init) {
  19. return;
  20. }
  21. this.m_init = true;
  22. this.m_parentContainer = null;
  23. this.m_display_list = (this.m_display_list || []);
  24. },
  25. setSize : function(w, h) {
  26. if(null === this.m_parentContainer) {
  27. return;
  28. }
  29. this.m_parentContainer.style.width = w + "px";
  30. this.m_parentContainer.style.height = h + "px";
  31. },
  32. setParent : function(parent) {
  33. this.m_parentContainer = parent;
  34. this.m_parentContainer.style.position = "absolute";
  35. this.m_parentContainer.style.overflow = "hidden";
  36. // this.m_parentContainer.style.overflow = "visible";
  37. this.offsetLeft = this.m_parentContainer.offsetLeft;
  38. this.offsetTop = this.m_parentContainer.offsetTop;
  39. },
  40. setOffset : function(offx, offy) {
  41. this.offsetLeft = offx;
  42. this.offsetTop = offy;
  43. },
  44. getOffsetX : function() {
  45. this.offsetLeft = this.m_parentContainer.offsetLeft;
  46. return this.offsetLeft;
  47. },
  48. getOffsetY : function() {
  49. this.offsetTop = this.m_parentContainer.offsetTop;
  50. return this.offsetTop;
  51. },
  52. setOverflow : function(value) {
  53. if(this.m_parentContainer) {
  54. this.m_parentContainer.style.overflow = value;
  55. }
  56. },
  57. onmousemove : function(evt) {
  58. var test = 0;
  59. test = 5;
  60. },
  61. addChild : function(display) {
  62. this.m_parentContainer.appendChild(display);
  63. this.m_display_list.push(display);
  64. },
  65. removeChild : function(display) {
  66. var index = -1;
  67. for(index = 0; index < this.m_parentContainer.childNodes.length; index++) {
  68. if(display == this.m_parentContainer.childNodes[index])
  69. {
  70. this.m_parentContainer.removeChild(display);
  71. break;
  72. }
  73. }
  74. index = ArrayIndexof(this.m_display_list, display);
  75. if(-1 !== index) {
  76. this.m_display_list.splice(index, 1);
  77. }
  78. },
  79. removeAllChild : function() {
  80. var display = null;
  81. while(this.m_display_list.length > 0) {
  82. display = this.m_display_list.pop();
  83. if(this.m_parentContainer.contains(display)) {
  84. this.m_parentContainer.removeChild(display);
  85. }
  86. }
  87. }
  88. };
  89. })();