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

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>

相关文章:

  • mysql用户名怎么看
  • H5自适应响应式代理记账与财政咨询服务类PbootCMS网站模板 – HTML5财务会计类网站源码下载
  • 【设计模式】02-理解常见设计模式-结构型模式
  • 一种微波场刺激器系统介绍
  • Molecular Communication(分子通信)与 Molecular Semantic Communication(分子语义通信)
  • 跟着李沐老师学习深度学习(十一)
  • 【LLM强化学习】LLM 强化学习中 Critic 模型训练详解
  • 基于逻辑概率的语义信道容量(Semantic Channel Capacity)和语义压缩理论(Semantic Compression Theory)
  • HTTP 请求方式`application/x-www-form-urlencoded` 与 `application/json` 怎么用?有什么区别?
  • 轻量级在线ETL数据集成工具架构设计与技术实现深度剖析
  • 网页五子棋——通用模块
  • leetcode:627. 变更性别(SQL解法)
  • WEB安全--SQL注入--INTO OUTFILE
  • 学习星开源在线考试教育系统
  • 在项目中操作 MySQL
  • UE WebUI插件依赖插件JsonLibrary 插件使用笔记
  • 「软件设计模式」适配器模式
  • 总结:使用JDK原生HttpsURLConnection,封装HttpsUtil工具类,加载自定义证书验证,忽略ssl证书验证
  • python 的框架 dash 开发TodoList Web 应用
  • 【外卖店优先级——模拟】
  • wordpress技术博客主题/温州seo结算
  • 网站图片模板/aso安卓优化
  • 源码猫网站建设ym361/谷歌浏览器网页
  • 介绍自己的家乡遵义网站建设/微信推广方法
  • 客户做网站嫌贵了/设计网站大全
  • 招投标网站开发公司/seo应用领域有哪些