web第三次作业

弹窗案例

1.首页代码

html 复制代码
<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>综合案例</title>

    <style>

        *{

            margin: 0;

            padding: 0;

            box-sizing: border-box;

        }

        html,body{

            width: 100%;

            height: 100%;

        }

        .container{

            width: 100%;

            height: 100%;

            background-color: #f2f1f2;

        }

        header{

            width: 1200px;

            height: 50px;

            background-color: #fff;

            margin: 0 auto;

            display: flex;

            justify-content: space-between;

            align-items: center;

        }

        header div:nth-of-type(2){

            display: flex;

            gap: 20px;

            cursor: pointer;

        }

        header div:nth-of-type(2) span:hover{

            font-weight: bolder;

            color: red;

        }

        .login-box{

            display: none;    

            overflow: hidden;

            width: 300px;

            height: 200px;

            background-color: #fff;

            border: solid 1px orangered;

            border-radius: 8px;

            box-shadow: rgba(255,0,0,0.5) 5px 5px 5px;

            position: absolute;

            left: 1150px;

            top: 50px;

        }

        .login-box .header{

            height: 40px;

            background-color: orangered;

            display: flex;

            justify-content: space-between;

            align-items: center;

            color: white;

            cursor: pointer;

            padding: 0 10px;

        }

    </style>

</head>

<body>

    <div class="container">

        <header>

            <div>

                <span>欢迎访问OPENLAB EDU</span>

            </div>

            <div>

                <span id="login">登录</span>

                <span id="register">注册</span>

            </div>

            <div class="login-box" id="login-box">

                <div class="header" id="header">

                    <span>会员登录</span>

                    <span id="close">[关闭]</span>

                </div>

            </div>

        </header>

    </div>



    <script>

        let _login=document.getElementById("login");

        let _login_box=document.getElementById("login-box");



        _login.onclick=function(){

            _login_box.style.display="block";

        }



        let _close=document.getElementById("close");

        _close.onclick=function(){

            _login_box.style.display="none";

        }



        let _header=document.getElementById("header");



        document.onmousedown=function(event){

            let offsetX=event.offsetX;

            let offsetY=event.offsetY;



            _header.onmousemove=function(event2){

                let mouseX=event2.clientX;

                let mouseY=event2.clientY;



                let loginX=mouseX-offsetX;

                let loginY=mouseY-offsetY;



                if(loginX<=0){

                    loginX=0;

                }

                if(loginY<=0){

                    loginY=0;

                }



                let iw=window.innerWidth;

                let lw=getComputedStyle(_login_box).width;

                lw=parseInt(lw);

                if(loginX>=(iw-lw)){

                    loginX=iw-lw;

                }

                let ih=window.innerHeight;

                let lh=getComputedStyle(_login_box).height;

                lh=parseInt(lh);

                if(loginY>=(ih-lh)){

                    loginY=ih-lh;

                }



                _login_box.style.left=loginX+"px";

                _login_box.style.top=loginY+"px";

            }

        }

        document.onmouseup=function(){

            _header.onmousemove=null;

        }

    </script>

</body>

</html>

2.展示效果

相关推荐
集成显卡36 分钟前
PlayWright | 初识微软出品的 WEB 应用自动化测试框架
前端·chrome·测试工具·microsoft·自动化·edge浏览器
前端小趴菜051 小时前
React - 组件通信
前端·react.js·前端框架
Amy_cx2 小时前
在表单输入框按回车页面刷新的问题
前端·elementui
dancing9992 小时前
cocos3.X的oops框架oops-plugin-excel-to-json改进兼容多表单导出功能
前端·javascript·typescript·游戏程序
后海 0_o2 小时前
2025前端微服务 - 无界 的实战应用
前端·微服务·架构
Scabbards_2 小时前
CPT304-2425-S2-Software Engineering II
前端
小满zs3 小时前
Zustand 第二章(状态处理)
前端·react.js
程序猿小D3 小时前
第16节 Node.js 文件系统
linux·服务器·前端·node.js·编辑器·vim
萌萌哒草头将军3 小时前
🚀🚀🚀Prisma 发布无 Rust 引擎预览版,安装和使用更轻量;支持任何 ORM 连接引擎;支持自动备份...
前端·javascript·vue.js
狼性书生3 小时前
uniapp实现的简约美观的星级评分组件
前端·uni-app·vue·组件