zoukankan      html  css  js  c++  java
  • js实现窗口拖拽最大最小化

    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            * {
                margin: 0;
                padding: 0;
            }

            .box {
                 400px;
                height: 300px;
                background-color: rgb(83, 36, 46);
                font-size: 40px;
                color: cyan;
                line-height: 300px;
                text-align: center;
                position: fixed;
                left: 0;
                right: 0;
                top: 0;
                bottom: 0;
            }
        </style>
    </head>

    <body>
        <div class="box">窗口</div>
    </body>

    </html>
    <script>
        var obox = document.querySelector(".box");
        //鼠标按下拖动
        obox.onmousedown = function (e) {
            var e = e || event;
            var offsetX = e.offsetX;
            var offsetY = e.offsetY;
            document.onmousemove = function (e) {
                var e = e || event;
                var l = e.pageX - offsetX;
                var t = e.pageY - offsetY;
                var maxl = window.innerWidth - obox.offsetWidth;
                var maxt = window.innerHeight - obox.offsetHeight;
                if (l < 0) {
                    l = 0;
                }
                if (l > maxl) {
                    l = maxl;
                }
                if (t < 0) {
                    t = 0;
                }
                if (t > maxt) {
                    t = maxt;
                }
                obox.style.left = l + "px";
                obox.style.top = t + "px";
            }
            document.onmouseup = function (e) {
                var e = e || event;
                document.onmousemove = null;
            }
        }
        // 双击变大变小
        var tp = 1;
        obox.ondblclick = function () {
            if (tp == 1) {
                obox.style.width = window.innerWidth + "px";
                obox.style.height = window.innerHeight + "px";
                tp = 2;
            } else {
                obox.style.width = 400 + "px";
                obox.style.height = 300 + "px";
                tp = 1;
            }
        }
    </script>
  • 相关阅读:
    服务器时间不准导致 com.sun.facelets.impl.DefaultFacelet refresh
    推荐10款来自极客标签的超棒前端特效[第五期] java程序员
    IE10的市场占有率扩充了一倍 java程序员
    固定背景实现的背景滚动特效 java程序员
    支持触摸设备的响应式HTML5音频播放器 AudioPlayer.js java程序员
    WebRTC与Ace在线代码编辑器合作,实现实时协作编程 java程序员
    最流行的JavaScript库,jQuery不再支持IE旧版本 java程序员
    Jquery实现鼠标移上弹出提示框,移出消失 java程序员
    xxx.c: Error: C3065E: type of input file 'xxxx' unknown java程序员
    35+多用途WordPress主题 java程序员
  • 原文地址:https://www.cnblogs.com/bwnnxxx123/p/13036481.html
Copyright © 2011-2022 走看看