You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

resizeable_table.js 3.7 kB

10 years ago
​
​
10 years ago
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
10 years ago
​
​
​
10 years ago
​
10 years ago
10 years ago
​
​
​
​
​
​
​
​
10 years ago
10 years ago
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * Created by ttang on 2016/5/24.
  3. */
  4. /* $(document).ready(function(){
  5. $("th").each(function(){
  6. $(this).css("width",$(this).width()-1);
  7. });
  8. resizeable_table = function(colS,colE,p1,p2){
  9. var headerTds = document.getElementById("homework_table").rows[0].cells;
  10. var mousedown = false;
  11. var resizeable = false;
  12. var targetTd;
  13. var screenXStart =0;
  14. var tdWidth = 0;
  15. var headerWidth = 0;
  16. var tblObj = document.getElementById("homework_table");
  17. var tblWidth = tblObj.offsetWidth;
  18. for(var i = colS;i<colE;i++){
  19. addListener(headerTds[i],"mousedown",onmousedown);
  20. addListener(headerTds[i],"mousemove",onmousemove);
  21. addListener(headerTds[i],"mouseup",onmouseup);
  22. }
  23. function onmousedown(event){
  24. if (resizeable == true){
  25. var evt =event||window.event;
  26. mousedown = true;
  27. screenXStart = evt.screenX;
  28. tdWidth = targetTd.offsetWidth;
  29. tdWidth2 = targetTd.nextElementSibling.offsetWidth;
  30. totalWidth = tdWidth + tdWidth2;
  31. }
  32. }
  33. function onmousemove(event){
  34. var evt =event||window.event;
  35. var srcObj = getTarget(evt);
  36. var offsetX = evt.offsetX || (evt.clientX - srcObj.getBoundingClientRect().left);//这个比较关键,解决了Firefox无offsetX属性的问题
  37. if (mousedown == true){
  38. var width = (tdWidth + (evt.screenX - screenXStart)) - p1 + "px";//计算后的新的宽度
  39. var width2 = (tdWidth2 - (evt.screenX - screenXStart)) - p2 + "px";
  40. if (parseInt(width)<5 || parseInt(width2)<5 || tdWidth > totalWidth || tdWidth2 > totalWidth){
  41. tartgetTd = null;
  42. resizeable = false;
  43. mousedown = false;
  44. }else{
  45. targetTd.style.width = width;
  46. targetTd.nextElementSibling.style.width = width2;
  47. }
  48. }else{
  49. var trObj = tblObj.rows[0];
  50. if(srcObj.offsetWidth - offsetX <=5){//实际改变本单元格列宽
  51. targetTd=srcObj;
  52. resizeable = true;
  53. for(var i = colS;i<colE;i++){
  54. headerTds[i].style.cursor='col-resize';//修改光标样式
  55. };
  56. }else{
  57. resizeable = false;
  58. mousedown = false;
  59. srcObj.style.cursor='default';
  60. }
  61. }
  62. }
  63. function onmouseup(event){
  64. tartgetTd = null;
  65. resizeable = false;
  66. mousedown = false;
  67. document.body.style.cursor='default';
  68. }
  69. document.body.onmouseup = function(event){
  70. tartgetTd = null;
  71. resizeable = false;
  72. mousedown = false;
  73. document.body.style.cursor='default';
  74. }
  75. function getTarget(evt){
  76. return evt.target || evt.srcElement;
  77. }
  78. function addListener(element,type,listener,useCapture){
  79. element.addEventListener?element.addEventListener(type,listener,useCapture):element.attachEvent("on" + type,listener);
  80. }
  81. }
  82. });
  83. */

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...