移动按钮

 

<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.0   Transitional//EN">  
  <html>  
  <head>  
  <title></title>  
  <meta   name="GENERATOR"   content="Microsoft   Visual   Studio   .NET   7.1">  
  <meta   name="vs_targetSchema"   content="http://schemas.microsoft.com/intellisense/ie5">  
  <script>  
  ///  
  //           This   script   was   designed   by   Erik   Arvidsson   for   WebFX                     //  
  //                                                                                                                                       //  
  //           For   more   info   and   examples   see:   http://webfx.eae.net                     //  
  //           or   contact   Erik   at   http://webfx.eae.net/contact.html#erik           //  
  //                                                                                                                                       //  
  //           Feel   free   to   use   this   code   as   lomg   as   this   disclaimer   is             //  
  //           intact.                                                                                                               //  
  ///  
   
  var   checkZIndex   =   true;  
   
  var   dragobject   =   null;  
  var   tx;  
  var   ty;  
   
  var   ie5   =   document.all   !=   null   &&   document.getElementsByTagName   !=   null;  
   
  function   getReal(el)   {  
  temp   =   el;  
   
  while   ((temp   !=   null)   &&   (temp.tagName   !=   "BODY"))   {  
  if   ((temp.className   ==   "moveme")   ||   (temp.className   ==   "handle")){  
  el   =   temp;  
  return   el;  
  }  
  temp   =   temp.parentElement;  
  }  
  return   el;  
  }  
   
   
  function   moveme_onmousedown()   {  
  el   =   getReal(window.event.srcElement)  
   
  if   (el.className   ==   "moveme"   ||   el.className   ==   "handle")   {  
  if   (el.className   ==   "handle")   {  
  tmp   =   el.getAttribute("handlefor");  
  if   (tmp   ==   null)   {  
  dragobject   =   null;  
  return;  
  }  
  else  
  dragobject   =   eval(tmp);  
  }  
  else    
  dragobject   =   el;  
   
  if   (checkZIndex)   makeOnTop(dragobject);  
   
  ty   =   window.event.clientY   -   getTopPos(dragobject);  
  tx   =   window.event.clientX   -   getLeftPos(dragobject);  
   
  window.event.returnValue   =   false;  
  window.event.cancelBubble   =   true;  
  }  
  else   {  
  dragobject   =   null;  
  }  
  }  
   
  function   moveme_onmouseup()   {  
  if(dragobject)   {  
  dragobject   =   null;  
  }  
  }  
   
  function   moveme_onmousemove()   {  
  if   (dragobject)   {  
  if   (window.event.clientX   >=   0   &&   window.event.clientY   >=   0)   {  
  dragobject.style.left   =   window.event.clientX   -   tx;  
  dragobject.style.top   =   window.event.clientY   -   ty;  
  }  
  window.event.returnValue   =   false;  
  window.event.cancelBubble   =   true;  
  }  
  }  
   
  function   getLeftPos(el)   {  
  if   (ie5)   {  
  if   (el.currentStyle.left   ==   "auto")  
  return   0;  
  else  
  return   parseInt(el.currentStyle.left);  
  }  
  else   {  
  return   el.style.pixelLeft;  
  }  
  }  
   
  function   getTopPos(el)   {  
  if   (ie5)   {  
  if   (el.currentStyle.top   ==   "auto")  
  return   0;  
  else  
  return   parseInt(el.currentStyle.top);  
  }  
  else   {  
  return   el.style.pixelTop;  
  }  
  }  
   
  function   makeOnTop(el)   {  
  var   daiz;  
  var   max   =   0;  
  var   da   =   document.all;  
   
  for   (var   i=0;   i<da.length;   i++)   {  
  daiz   =   da[i].style.zIndex;  
  if   (daiz   !=   ""   &&   daiz   >   max)  
  max   =   daiz;  
  }  
   
  el.style.zIndex   =   max   +   1;  
  }  
   
  if   (document.all)   {   //This   only   works   in   IE4   or   better  
  document.onmousedown   =   moveme_onmousedown;  
  document.onmouseup   =   moveme_onmouseup;  
  document.onmousemove   =   moveme_onmousemove;  
  }  
   
  document.write("<style>");  
  document.write(".moveme {cursor:   move;position:relative}");  
  document.write(".handle {cursor:   move;}");  
  document.write("</style>");  
   
  function   keypress(){  
  var   key=window.event.keyCode;  
  if(key==27){  
  txtInput.value   ="";  
  txtInput.style.display   ="none";  
  }  
  if(key==13){  
  var   txt=document.createElement("span");  
  txt.className="moveme";  
  txt.innerText=txtInput.value   ;  
  txtInput.value   ="";  
  txt.style.postion="absolute";  
  txt.style.left=window.event.clientX;  
  txt.style.top=window.event.clientY;  
  txtInput.style.display   ="none";  
  document.body.appendChild(txt);  
  }  
  }  
   
  </script>  
  </head>  
  <body>  
  <div   id="my"   style="position:absolute;height:50px;width:150px;border:1px   solid   activecaption">  
  <div   class="handle"   handlefor="my"   style="background:activecaption;color:window"   title="移动按钮">移动按钮</div>  
  <input   type="button"   value="添加文字"   οnclick="txtInput.style.display='block'">   
  <input   type="text"   title="回车添加    
  ESC取消"   id="txtInput"     style="display:none"   οnkeypress="keypress()"  
  >  
  </div>  
  </body>  
  </html>  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值