• 鼠标移动 登陆框跟随


    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <meta name="Generator" content="EditPlus®">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <title>鼠标移动 登陆框跟随</title>
     </head>
     <style type="text/css">
       head,body{
         margin:0;
         padding:0;
      }
    
       .top{
         height:30px;
         background:#336699;
         padding-left:20px;
         color:white;
         line-height:30px;
       }
       .regBox{
          310px;
          position:absolute;
          top:228px;
          left:528px;
    
       }
       .register{
         cursor:pointer;
       }
       .regMessage{
          300px;
          height:200px;
          display:none;
          border:5px solid #c0c0c0;
       }
       .regMessage .dt{
         background:#336666;
         height:30px;
         line-height:30px;
         color:#fbfbfb;
       }
       .regMessage .dt span{
          
          cursor:move;
    
       }
       .regMessage .dt span:nth-child(1){
         float:left;
       }
       .regMessage .dt span:nth-child(2){
         float:right;
       }
     
      </style>
     <body>
      <div class="top">
        <span class="register">注册登陆</span>
      </div>
        
        <div class="regBox">
       <div  class="regMessage">
           <div class="dt"><span>注册信息 (可以拖拽) </span><span class="close">【关闭】</span></div>
       </div>
       </div>
       <script type="text/javascript">
    
          function show(ele){
            ele.style.display="block";
          }
    
          function hide(ele){
             ele.style.display="none";
          };
         var register= document.querySelector(".register");
         var regMessage = document.querySelector(".regMessage");
          var regBox = document.querySelector(".regBox");
         var close = document.querySelector(".close");
                 register.addEventListener("click",function(e)
                 {
                     show(regMessage);
                 },false);
    
                  close.addEventListener("click",function(e)
                 {
                    e.stopPropagation();
                     hide(regMessage);
                 },false);
    
                regMessage.children[0].onmousedown=function(event){
                        
                          var  e=event||window.event; 
                          var left=e.clientX-regBox.offsetLeft;
                          var top=e.clientY-regBox.offsetTop;
                    document.onmousemove=function(event){
                           var  event=event||window.event; 
                           var  x=event.clientX-left;
                           var  y=event.clientY-top;
                           //边界检测
                          if(x<=0){
                            x=0;
                            
                          }
                          if(x>=1366-regBox.offsetWidth){
                            x=1366-regBox.offsetWidth;
                        
                          }
    
                          if(y<=0){
                            y=0;
                            
                          }
    
                          if(y>=600-regBox.offsetHeight){
                            y=600-regBox.offsetHeight;
                            
                          }
                        
                           regBox.style.top=y+"px";
                           regBox.style.left=x+"px";
                           //防止移动的过程选中字体  字体也是大盒子的一部分 
                           //所以移动的时候  选中之后 即使抬起鼠标也会移动
    
                           window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
                    }
             regMessage.children[0].onmouseup=function(){
                     document.onmousemove=null;
                }
                
                }
                
    
       </script>
     </body>
    </html>
  • 相关阅读:
    JavaScript学习之路-语法
    JavaScript学习之路-语法
    JavaScript学习之路-为什么要学习JavaScript语法
    JavaScript学习之路-为什么要学习JavaScript语法
    net4:Panel动态添加控件及隐藏,Table动态创建表格
    net1:DateTime,Application与Session,
    C#精髓第四讲 GridView 72般绝技
    J2ME开发基本语法及小实例专题
    net6:创建Membership对象数据源的代码
    net4:GridView中的重要操作(添加checkbox,以及鼠标动作,行颜色等)
  • 原文地址:https://www.cnblogs.com/liveoutfun/p/9295537.html
Copyright © 2020-2023  润新知