当前位置: 首页 > article >正文

web前端第三次作业

题目

本期作业
WEB第三次作业
请使用JS实一个网页中登录窗口的显示/隐藏,页面中拖动移动,并且添加了边界判断的网页效

代码图片

效果展示

代码

<!DOCTYPE html>

<html lang="zh">

<head>

    <meta charset="UTF-8">

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

    <title>Document</title>

</head>

<style>

    *{

        margin: 0;padding: 0;box-sizing: border-box;}

        html,body{width: 100%;height: 100%;}

        .container{width: 100%;height: 100%;background-color: #f2f1f2f2;}

        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-last-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>

<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.οnclick=function() {

            _login_box.style.display ="block";        

        }

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

        _close.οnclick=function( ){

            _login_box.style.display="none";

        }

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

        document.οnmοusedοwn= function(event){

            let offsetX =event.offsetX;

            let offsetY =event.offsetY;

            _header.οnmοusemοve=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.οnmοuseup=function(){

            _header.οnmοusemοve=null;

        }

    </script>

</body>

</html>


http://www.kler.cn/a/543569.html

相关文章:

  • Rust 中的闭包:捕获环境的匿名函数
  • hot100_23. 合并 K 个升序链表
  • 搜维尔科技在动作捕捉与动画制作、汽车制造与安全测试、机器人与自动化领域的一些案例
  • 局域网内别的电脑怎么连接到对方的mysql数据库
  • 保研考研机试攻略:python笔记(4)
  • 支付宝安全发全套解决方案
  • 32单片机学习记录3之基本外设的使用
  • 解析RK3588无线边缘盒子为工业自动化边缘推理带来的 AI 突破
  • ComfyUI流程图生图原理详解
  • halcon三维点云数据处理(十四)在3D场景中去除背景的三种方式
  • [SAP ABAP] OO ALV报表练习1
  • 算法与数据结构(合并两个有序数组)
  • OpenCV2D 特征框架 (24)处理矩形框集合函数groupRectangles()的使用
  • 免费体验,一键部署!Alaya NeW应用市场正式上线DeepSeek系列模型
  • Linux零基础快速入门(非常详细),全覆盖Linux的基础知识,看完这一篇就够了。
  • 基于CanMV IDE 开发软件对K210图像识别模块的开发
  • 基于单片机的仓库安防系统(论文+源码)
  • (篇六)基于PyDracula搭建一个深度学习的软件之新版本ultralytics-8.3.28调试
  • 机器学习 - 机器学习模型的评价指标
  • HackerRank C++面试,中等难度题目 - Attribute Parser
  • 【C++高并发服务器WebServer】-18:事件处理模式与线程池
  • 基于Java的分布式系统架构设计与实现
  • Kafka的ISR是什么,HW是什么,怎么保证可靠性,Kafka怎么实现顺序消息?为什么Kafka的broker上的topic越多,效率越慢?
  • 嵌入式WebRTC压缩至670K,目标将so动态库压缩至500K,.a静态库还可以更小
  • 基于SpringBoot+Vue的扶贫助农管理系统
  • ubuntu下ollama/vllm两种方式在本地部署Deepseek-R1