tuodong.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. var get = {
  2. byId: function(id) {
  3. return typeof id === "string" ? document.getElementById(id) : id
  4. },
  5. byClass: function(sClass, oParent) {
  6. var aClass = [];
  7. var reClass = new RegExp("(^| )" + sClass + "( |$)");
  8. var aElem = this.byTagName("*", oParent);
  9. for (var i = 0; i < aElem.length; i++) reClass.test(aElem[i].className) && aClass.push(aElem[i]);
  10. return aClass
  11. },
  12. byTagName: function(elem, obj) {
  13. return (obj || document).getElementsByTagName(elem)
  14. }
  15. };
  16. var dragMinWidth = 800;
  17. var dragMinHeight = 600;
  18. /*-------------------------- +
  19. 拖拽函数
  20. +-------------------------- */
  21. function drag(oDrag, handle){
  22. var disX = 0;
  23. var disY = 0;
  24. var oMax = get.byClass("max", oDrag)[0];
  25. var oRevert = get.byClass("revert", oDrag)[0];
  26. var oClose = get.byClass("close", oDrag)[0];
  27. var allMap = document.getElementById("allmap");
  28. handle = handle || oDrag;
  29. handle.style.cursor = "move";
  30. handle.onmousedown = function (event){
  31. var event = event || window.event;
  32. disX = event.clientX - oDrag.offsetLeft;
  33. disY = event.clientY - oDrag.offsetTop;
  34. document.onmousemove = function (event){
  35. var event = event || window.event;
  36. var iL = event.clientX - disX;
  37. var iT = event.clientY - disY;
  38. var maxL = document.documentElement.clientWidth - oDrag.offsetWidth;
  39. var maxT = document.documentElement.clientHeight - oDrag.offsetHeight+document.body.scrollTop;
  40. iL <= 0 && (iL = 0);
  41. iT <= 0 && (iT = 0);
  42. iL >= maxL && (iL = maxL);
  43. iT >= maxT && (iT = maxT);
  44. oDrag.style.left = iL + "px";
  45. oDrag.style.top = iT + "px";
  46. return false
  47. };
  48. document.onmouseup = function (){
  49. document.onmousemove = null;
  50. document.onmouseup = null;
  51. this.releaseCapture && this.releaseCapture()
  52. };
  53. this.setCapture && this.setCapture();
  54. return false
  55. };
  56. //最大化按钮
  57. oMax.onclick = function (){
  58. oDrag.style.top = oDrag.style.left = 0;
  59. //整个窗体
  60. oDrag.style.width = document.documentElement.clientWidth - 2 + "px";
  61. oDrag.style.height = document.documentElement.clientHeight - 2 + "px";
  62. //地图大小
  63. allMap.style.width = document.documentElement.clientWidth - 15 + "px";
  64. allMap.style.height = document.documentElement.clientHeight - 100 + "px";
  65. this.style.display = "none";
  66. oRevert.style.display = "block";
  67. };
  68. //还原按钮
  69. oRevert.onclick = function (){
  70. oDrag.style.width = dragMinWidth + "px";
  71. oDrag.style.height = dragMinHeight + "px";
  72. oDrag.style.left = (document.documentElement.clientWidth - oDrag.offsetWidth) / 2 + "px";
  73. oDrag.style.top = (document.documentElement.clientHeight - oDrag.offsetHeight) / 2 + "px";
  74. //地图大小
  75. allMap.style.width = "790px";
  76. allMap.style.height = "500px";
  77. this.style.display = "none";
  78. oMax.style.display = "block";
  79. };
  80. //关闭按钮
  81. oClose.onclick = function (){
  82. map.clearOverlays();
  83. document.getElementById("lng").value = '';
  84. document.getElementById("lat").value = '';
  85. oDrag.style.display = "none";
  86. };
  87. }
  88. window.onload = window.onresize = function (){
  89. var oDrag = document.getElementById("drag");
  90. var oTitle = get.byClass("title", oDrag)[0];
  91. drag(oDrag, oTitle);
  92. oDrag.style.left = (document.documentElement.clientWidth - 800) / 2 + "px";
  93. oDrag.style.top = (document.documentElement.clientHeight - 600) / 2 + "px";
  94. };