moveitem.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. $(function(){
  2. //移动窗口,并置顶窗口 [显示红框]
  3. $(".myMoveItem .moveItem_title").bind("mousedown", function(e1){
  4. var _this = $(this).parents(".myMoveItem");
  5. var oldpageX = e1.pageX;
  6. var oldpageY = e1.pageY;
  7. var oldLeft = parseInt(_this.css("left"));
  8. var oldTop = parseInt(_this.css("top"));
  9. var _clone = _this.clone().empty().css({
  10. "border": "1px solid red",
  11. "background": "transparent",
  12. }).appendTo(_this.parent());
  13. setMoveItemToppest(_clone); //置顶
  14. $(document).bind("mousemove.myMoveItem", function(e2){
  15. _clone.css("left", e2.pageX - oldpageX + oldLeft + "px");
  16. _clone.css("top", e2.pageY - oldpageY + oldTop + "px");
  17. });
  18. $(document).bind("mouseup.myMoveItem", function(e2){
  19. setMoveItemToppest(_this); //置顶
  20. _this.css("left", parseInt(_clone.css("left")));
  21. _this.css("top", parseInt(_clone.css("top")));
  22. _clone.remove();
  23. $(document).unbind("mousemove.myMoveItem");
  24. $(document).unbind("mouseup.myMoveItem");
  25. });
  26. });
  27. //移动窗口,并置顶窗口 [不显示红框,直接移动] [使用方法:取消这个注释,然后注释上面那个]
  28. // $(".myMoveItem .moveItem_title").bind("mousedown", function(e1){
  29. // var _this = $(this).parents(".myMoveItem");
  30. // var oldpageX = e1.pageX;
  31. // var oldpageY = e1.pageY;
  32. // var oldLeft = parseInt(_this.css("left"));
  33. // var oldTop = parseInt(_this.css("top"));
  34. // setMoveItemToppest(_this); //置顶
  35. // $(document).bind("mousemove.myMoveItem", function(e2){
  36. // _this.css("left", e2.pageX - oldpageX + oldLeft + "px");
  37. // _this.css("top", e2.pageY - oldpageY + oldTop + "px");
  38. // });
  39. // $(document).bind("mouseup.myMoveItem", function(e2){
  40. // $(document).unbind("mousemove.myMoveItem");
  41. // $(document).unbind("mouseup.myMoveItem");
  42. // });
  43. // });
  44. //点击时置顶
  45. $(".myMoveItem").bind("click", function(){
  46. setMoveItemToppest($(this));
  47. });
  48. //置顶窗口方法
  49. function setMoveItemToppest(_this){
  50. function sortNumber(a, b) {return a-b;}
  51. var zIndexArr = [];
  52. $(document).find(".myMoveItem").each(function(){
  53. zIndexArr.push(parseInt($(this).css("z-index")));
  54. });
  55. zIndexArr.sort(sortNumber);
  56. _this.css("z-index", zIndexArr[zIndexArr.length-1] + 1);
  57. }
  58. //右下角改变窗口大小
  59. $(".myMoveItem .moveItem_resize").bind("mousedown", function(e1){
  60. var _this = $(this).parents(".myMoveItem");
  61. var oldpageX = e1.pageX;
  62. var oldpageY = e1.pageY;
  63. var oldWidth = parseInt(_this.css("width"));
  64. var oldHeight = parseInt(_this.css("height"));
  65. $(document).bind("mousemove.myMoveItem", function(e2){
  66. if((e2.pageX - oldpageX + oldWidth) > 150 && (e2.pageY - oldpageY + oldHeight) > 150){
  67. _this.css("width", e2.pageX - oldpageX + oldWidth + "px");
  68. _this.css("height", e2.pageY - oldpageY + oldHeight + "px");
  69. // _this.children(".moveItem_body").css("height", "calc(100% - 95px)");
  70. }
  71. });
  72. $(document).bind("mouseup.myMoveItem", function(e2){
  73. $(document).unbind("mousemove.myMoveItem");
  74. $(document).unbind("mouseup.myMoveItem");
  75. });
  76. });
  77. //关闭按钮
  78. $(".myMoveItem .moveItem_close").click(function(){
  79. $(this).parents(".moveItem_header").parent().hide();
  80. });
  81. //取消按钮
  82. $(".myMoveItem .moveItem_cancel").click(function(){
  83. $(this).parents(".moveItem_footer").parent().remove();
  84. });
  85. //全屏按钮
  86. $(".moveItem_fullScreen").click(function(e){
  87. $(this).hide();
  88. $(this).siblings(".moveItem_normalScreen").attr("css-data", $(this).parents(".moveItem_header").parent().attr("style"));
  89. $(this).parents(".moveItem_header").parent().css({
  90. "left":"0",
  91. "top":"0",
  92. "height":"100%",
  93. "width":"100%",
  94. });
  95. // $(this).parents(".myMoveItem").children(".moveItem_body").css("height", "calc(100% - 95px)");
  96. $(this).siblings(".moveItem_normalScreen").show();
  97. });
  98. //还原按钮
  99. $(".moveItem_normalScreen").click(function(){
  100. $(this).parents(".moveItem_header").parent().attr("style", $(this).attr("css-data"));
  101. $(this).hide();
  102. $(this).siblings(".moveItem_fullScreen").show();
  103. });
  104. });