zoukankan      html  css  js  c++  java
  • JavaScript登陆弹窗,可拖拽

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>JavaScript登陆弹窗,可拖拽</title>
    <style type="text/css">
    * { margin:0; padding:0; }
    #box { 400px; height:200px; background:#f9f9f9; border:1px solid #ccc; position:absolute; left:50%; top:50%; margin:-100px 0 0 -200px; border-radius:4px; box-shadow:0 0 15px #ddd; }
    .title { padding:10px 20px; background-color:#f1f1f1; border-bottom:1px solid #ddd; font-size:14px; color:#333; }
    .login { padding:30px 0 0 50px; }
    .login p { margin-bottom:10px; font-size:14px; }
    .login input.text { 200px; padding:5px; border:1px solid #ddd; vertical-align:middle; }
    .login input.btn { 70px; padding:6px; border:1px solid #ddd; margin-left:41px; cursor:pointer; }
    </style>
    </head>
    
    <body>
    
    <div id="box">
        <h2 class="title">用户登录</h2>
        <div class="login">
        <form action="">
            <p><label>账户:</label><input type="text" name="" id="" class="text"></p>
            <p><label>密码:</label><input type="text" name="" id="" class="text"></p>
            <p><input type="submit" name="" id="" value="提 交" class="btn"></p>
        </form>
        </div>
    </div>
    
    
    <script type="text/javascript">
    window.onload = function(){
        var oBox = document.getElementById("box");
        var oBtn = oBox.getElementsByTagName("h2")[0];
        var disX = 0;
        var disY = 0;
        oBtn.onmousedown = function(ev){
            var oEvent = ev||event;
            disX = oEvent.clientX-oBox.offsetLeft;
            disY = oEvent.clientY-oBox.offsetTop;
            oBox.style.cursor = "crosshair";
            document.onmousemove = function(ev){
                var oEvent = ev||event;
                var l = oEvent.clientX-disX;
                var t = oEvent.clientY-disY;
                oBox.style.margin = 0;
                if(l<0){
                    l=0;
                }else if(l>document.documentElement.clientWidth-oBox.offsetWidth){
                    l=document.documentElement.clientWidth-oBox.offsetWidth;
                }
                if(t<0){
                    t=0;
                }else if(t>document.documentElement.clientHeight-oBox.offsetHeight){
                    t=document.documentElement.clientHeight-oBox.offsetHeight;
                }
                oBox.style.left = l+"px";
                oBox.style.top = t+"px";
            }
            document.onmouseup = function(){
                document.onmousemove = null;
                document.onmouseup = null;
                oBox.style.cursor = "default";
            }
            return false;
        }
        window.onresize = function(){
            if(oBox.offsetLeft>document.documentElement.clientWidth-oBox.offsetWidth){
                oBox.style.left=document.documentElement.clientWidth-oBox.offsetWidth+"px";
            }
            if(oBox.offsetTop>document.documentElement.clientHeight-oBox.offsetHeight){
                oBox.style.top=document.documentElement.clientHeight-oBox.offsetHeight+"px";
    
            }
        }
    }
    </script>
    </body>
    </html>
  • 相关阅读:
    nodepad++中的正则表达式匹配和替换操作。
    QT Creator配置环境和安装
    圣诞树小程序的制作
    C#编辑xml文件
    delegate里的Invoke和BeginInvoke
    记录RFID操作错误
    关于Panel隐藏横向滚动条
    随笔
    Java图形打印 上下对称三角星
    Centos 7.5安装 Redis 5.0.0
  • 原文地址:https://www.cnblogs.com/huanlei/p/3116361.html
Copyright © 2011-2022 走看看