国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

javascript實(shí)現(xiàn)鼠標(biāo)拖動(dòng)改變層大小的方法

2024-05-06 16:19:04
字體:
供稿:網(wǎng)友

這篇文章主要介紹了javascript實(shí)現(xiàn)鼠標(biāo)拖動(dòng)改變層大小的方法,涉及javascript操作鼠標(biāo)事件及樣式的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了javascript實(shí)現(xiàn)鼠標(biāo)拖動(dòng)改變層大小的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

 

 
  1. <html> 
  2. <head> 
  3. <title>拖動(dòng)改變層的大小</title> 
  4. <meta content="text/html; charset=gb2312" http-equiv="Content-Type"
  5. <style> { 
  6. box-sizing: border-box; moz-box-sizing: border-box 
  7. #testDiv { background-color: buttonface; background-repeat: repeat;  
  8. background-attachment: scroll; color: #3969A5; height: 300px;  
  9. left: 30px; overflow: hidden; width: 500; z-index: 2;  
  10. border: 2px outset white; margin: 0px; padding: 2px;  
  11. background-position: 0% 50% } 
  12. body { font-family: Verdana; font-size: 9pt } 
  13. #innerNice { background-color: white; background-repeat: repeat; 
  14. background-attachment:  
  15. scroll; color: #3969A5; height: 100%; overflow: auto;  
  16. width: 100%; border: 2px inset white; padding: 8px;  
  17. background-position: 0% 50% } 
  18. </style> 
  19. <SCRIPT language=javascript> 
  20. var theobject = null;  
  21. function resizeObject() { 
  22. this.el = null//pointer to the object 
  23. this.dir = ""//type of current resize (n,s,e,w,ne,nw,se,sw) 
  24. this.grabx = null//Some useful values 
  25. this.graby = null
  26. this.width = null
  27. this.height = null
  28. this.left = null
  29. this.top = null
  30. function getDirection(el) { 
  31. var xPos, yPos, offset, dir; 
  32. dir = ""
  33. xPos = window.event.offsetX; 
  34. yPos = window.event.offsetY; 
  35. offset = 8; //The distance from the edge in pixels 
  36. if (yPos<offset) dir += "n"
  37. else if (yPos > el.offsetHeight-offset) dir += "s"
  38. if (xPos<offset) dir += "w"
  39. else if (xPos > el.offsetWidth-offset) dir += "e"
  40. return dir; 
  41. function doDown() { 
  42. var el = getReal(event.srcElement, "className""resizeMe"); 
  43. if (el == null) { 
  44. theobject = null
  45. return
  46. }  
  47. dir = getDirection(el); 
  48. if (dir == ""return
  49. theobject = new resizeObject(); 
  50. theobject.el = el; 
  51. theobject.dir = dir; 
  52. theobject.grabx = window.event.clientX; 
  53. theobject.graby = window.event.clientY; 
  54. theobject.width = el.offsetWidth; 
  55. theobject.height = el.offsetHeight; 
  56. theobject.left = el.offsetLeft; 
  57. theobject.top = el.offsetTop; 
  58. window.event.returnValue = false
  59. window.event.cancelBubble = true
  60. function doUp() { 
  61. if (theobject != null) { 
  62. theobject = null
  63. function doMove() { 
  64. var el, xPos, yPos, str, xMin, yMin; 
  65. xMin = 8; //The smallest width possible 
  66. yMin = 8; // height 
  67. el = getReal(event.srcElement, "className""resizeMe"); 
  68. if (el.className == "resizeMe") { 
  69. str = getDirection(el); 
  70. //Fix the cursor 
  71. if (str == "") str = "default"
  72. else str += "-resize"
  73. el.style.cursor = str; 
  74. //Dragging starts here 
  75. if(theobject != null) { 
  76. if (dir.indexOf("e") != -1) 
  77. theobject.el.style.width = Math.max(xMin, theobject.width + window.event.clientX - theobject.grabx) + "px"
  78. if (dir.indexOf("s") != -1) 
  79. theobject.el.style.height = Math.max(yMin, theobject.height + window.event.clientY - theobject.graby) + "px"
  80. if (dir.indexOf("w") != -1) { 
  81. theobject.el.style.left = Math.min(theobject.left + window.event.clientX - theobject.grabx, theobject.left + theobject.width - xMin) + "px"
  82. theobject.el.style.width = Math.max(xMin, theobject.width - window.event.clientX + theobject.grabx) + "px"
  83. if (dir.indexOf("n") != -1) { 
  84. theobject.el.style.top = Math.min(theobject.top + window.event.clientY - theobject.graby, theobject.top + theobject.height - yMin) + "px"
  85. theobject.el.style.height = Math.max(yMin, theobject.height - window.event.clientY + theobject.graby) + "px"
  86. window.event.returnValue = false
  87. window.event.cancelBubble = true
  88. }  
  89. function getReal(el, type, value) { 
  90. temp = el; 
  91. while ((temp != null) && (temp.tagName != "BODY")) { 
  92. if (eval("temp." + type) == value) { 
  93. el = temp; 
  94. return el; 
  95. temp = temp.parentElement; 
  96. return el; 
  97. document.onmousedown = doDown; 
  98. document.onmouseup = doUp; 
  99. document.onmousemove = doMove; 
  100. </SCRIPT> 
  101. </head> 
  102. <body> 
  103. <div class="resizeMe" id="testDiv"
  104. <div id="innerNice"
  105. <p align="center"> </p> 
  106. <p align="center"
  107. 請(qǐng)?jiān)谶吙蛱幫蟿?dòng)鼠標(biāo)</p> 
  108. <p> </p> 
  109. <p> </p> 
  110. <p> </p> 
  111. </div> 
  112. </div> 
  113. </body> 
  114. </html> 

希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 金阳县| 雷州市| 咸丰县| 台南县| 区。| 故城县| 措勤县| 康平县| 吐鲁番市| 汝城县| 扶余县| 蒙山县| 高阳县| 昌宁县| 本溪市| 呼玛县| 遵化市| 屏边| 华宁县| 阜新| 成武县| 阳曲县| 静海县| 厦门市| 江源县| 皮山县| 曲麻莱县| 广灵县| 鄢陵县| 蒲城县| 普安县| 盐亭县| 颍上县| 柳州市| 正镶白旗| 呼玛县| 西青区| 慈溪市| 渝北区| 上犹县| 济南市|