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>

相关推荐
发现一只大呆瓜1 天前
深度解密 Rollup 插件开发:核心钩子函数全生命周期图鉴
前端·vite
java_nn1 天前
一文了解前端技术
前端
发现一只大呆瓜1 天前
深度解析 Rollup 配置与 Vite 生产构建流程
前端·vite
小码哥_常1 天前
安卓黑科技:让手机成为你的“跌倒保镖”
前端
小李子呢02111 天前
前端八股Vue---Vue2和Vue3的区别,set up的用法
前端·javascript·vue.js
m0_647057961 天前
Harness Engineering 实践指南
前端
邂逅星河浪漫1 天前
【银行内网开发-管理端】Vue管理端+Auth后台开发+Nginx配置+Linux部署(详细解析)
linux·javascript·css·vue.js·nginx·html·前后端联调
JJay.1 天前
Android BLE 稳定连接的关键,不是扫描,而是 GATT 操作队列
android·服务器·前端
星空椰1 天前
JavaScript 进阶基础:函数、作用域与常用技巧总结
开发语言·前端·javascript
奔跑的呱呱牛1 天前
@giszhc/vue-page-motion:Vue3 路由动画怎么做才“丝滑”?(附在线示例)
前端·javascript·vue.js