floater.js
上传用户:jhtang88
上传日期:2014-01-27
资源大小:28528k
文件大小:5k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  2.   if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
  3.     document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  4.   else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
  5. }
  6. MM_reloadPage(true);
  7. // -->
  8. function MM_findObj(n, d) { //v4.0
  9.   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  10.     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  11.   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  12.   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  13.   if(!x && document.getElementById) x=document.getElementById(n); return x;
  14. }
  15. function MM_showHideLayers() { //v3.0
  16.   var i,p,v,obj,args=MM_showHideLayers.arguments;
  17.   for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
  18.     if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
  19.     obj.visibility=v; }
  20. }
  21. self.onError=null;
  22. currentX = currentY = 0;
  23. whichIt = null;
  24. lastScrollX = 0; lastScrollY = 0;
  25. NS = (document.layers) ? 1 : 0;
  26. IE = (document.all) ? 1: 0;
  27. <!-- STALKER CODE -->
  28. function heartBeat() {
  29. if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; }
  30. if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; }
  31. if(diffY != lastScrollY) {
  32. percent = .1 * (diffY - lastScrollY);
  33. if(percent > 0) percent = Math.ceil(percent);
  34. else percent = Math.floor(percent);
  35. if(IE) document.all.floater.style.pixelTop += percent;
  36. if(NS) document.floater.top += percent; 
  37. lastScrollY = lastScrollY + percent;
  38. }
  39. if(diffX != lastScrollX) {
  40. percent = .1 * (diffX - lastScrollX);
  41. if(percent > 0) percent = Math.ceil(percent);
  42. else percent = Math.floor(percent);
  43. if(IE) document.all.floater.style.pixelLeft += percent;
  44. if(NS) document.floater.left += percent;
  45. lastScrollX = lastScrollX + percent;
  46. }
  47. }
  48. <!-- /STALKER CODE -->
  49. <!-- DRAG DROP CODE -->
  50. function checkFocus(x,y) { 
  51. stalkerx = document.floater.pageX;
  52. stalkery = document.floater.pageY;
  53. stalkerwidth = document.floater.clip.width;
  54. stalkerheight = document.floater.clip.height;
  55. if( (x > stalkerx && x < (stalkerx+stalkerwidth)) && (y > stalkery && y < (stalkery+stalkerheight))) return true;
  56. else return false;
  57. }
  58. function grabIt(e) {
  59. if(IE) {
  60. whichIt = event.srcElement;
  61. while (whichIt.id.indexOf("floater") == -1) {
  62. whichIt = whichIt.parentElement;
  63. if (whichIt == null) { return true; }
  64. }
  65. whichIt.style.pixelLeft = whichIt.offsetLeft;
  66. whichIt.style.pixelTop = whichIt.offsetTop;
  67. currentX = (event.clientX + document.body.scrollLeft);
  68. currentY = (event.clientY + document.body.scrollTop);   
  69. } else { 
  70. window.captureEvents(Event.MOUSEMOVE);
  71. if(checkFocus (e.pageX,e.pageY)) { 
  72. whichIt = document.floater;
  73. StalkerTouchedX = e.pageX-document.floater.pageX;
  74. StalkerTouchedY = e.pageY-document.floater.pageY;
  75. }
  76. return true;
  77. }
  78. function moveIt(e) {
  79. if (whichIt == null) { return false; }
  80. if(IE) {
  81. newX = (event.clientX + document.body.scrollLeft);
  82. newY = (event.clientY + document.body.scrollTop);
  83. distanceX = (newX - currentX);    distanceY = (newY - currentY);
  84. currentX = newX;    currentY = newY;
  85. whichIt.style.pixelLeft += distanceX;
  86. whichIt.style.pixelTop += distanceY;
  87. if(whichIt.style.pixelTop < document.body.scrollTop) whichIt.style.pixelTop = document.body.scrollTop;
  88. if(whichIt.style.pixelLeft < document.body.scrollLeft) whichIt.style.pixelLeft = document.body.scrollLeft;
  89. if(whichIt.style.pixelLeft > document.body.offsetWidth - document.body.scrollLeft - whichIt.style.pixelWidth - 20) whichIt.style.pixelLeft = document.body.offsetWidth - whichIt.style.pixelWidth - 20;
  90. if(whichIt.style.pixelTop > document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5) whichIt.style.pixelTop = document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5;
  91. event.returnValue = false;
  92. } else { 
  93. whichIt.moveTo(e.pageX-StalkerTouchedX,e.pageY-StalkerTouchedY);
  94. if(whichIt.left < 0+self.pageXOffset) whichIt.left = 0+self.pageXOffset;
  95. if(whichIt.top < 0+self.pageYOffset) whichIt.top = 0+self.pageYOffset;
  96. if( (whichIt.left + whichIt.clip.width) >= (window.innerWidth+self.pageXOffset-17)) whichIt.left = ((window.innerWidth+self.pageXOffset)-whichIt.clip.width)-17;
  97. if( (whichIt.top + whichIt.clip.height) >= (window.innerHeight+self.pageYOffset-17)) whichIt.top = ((window.innerHeight+self.pageYOffset)-whichIt.clip.height)-17;
  98. return false;
  99. }
  100. return false;
  101. }
  102. function dropIt() {
  103. whichIt = null;
  104. if(NS) window.releaseEvents (Event.MOUSEMOVE);
  105. return true;
  106. }
  107. <!-- DRAG DROP CODE -->
  108. if(NS) {
  109. window.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN);
  110. window.onmousedown = grabIt;
  111. window.onmousemove = moveIt;
  112. window.onmouseup = dropIt;
  113. }
  114. if(IE) {
  115. document.onmousedown = grabIt;
  116. document.onmousemove = moveIt;
  117. document.onmouseup = dropIt;
  118. }
  119. if(NS || IE) action = window.setInterval("heartBeat()",1);