web第三次作业

实现网页登入窗口的显示隐藏

<!DOCTYPE html>

<html lang="zh">

<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>欢迎访问NDBNDB</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 + "px";

let loginY = mouseY - offsetY + "px";

_login_box.style.left = loginX;

_login_box.style.top = loginY;

}

}

document.onmouseup = function () {

_header.onmousemove = null;

}

</script>

</body>

</html>

相关推荐
一 乐5 小时前
游戏账号交易|基于Springboot+vue的游戏账号交易系统(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·后端·游戏
西洼工作室5 小时前
前端自制设备模拟器模拟不同终端展示效果
前端·css3·js·响应式开发
ByteCraze5 小时前
面向Nodejs开发人员MCP快速入门
前端·node.js·agent·mcp
chéng ௹5 小时前
前端转编码(encodeURIComponent)以及解码(decodeURIComponent)
开发语言·前端·javascript
温轻舟6 小时前
禁毒路上,任重道远 | HTML页面
开发语言·前端·javascript·css·html·温轻舟
likuolei6 小时前
XSL-FO 列表
前端·数据库
shaohaoyongchuang6 小时前
vue_03路由
前端·javascript·vue.js
我叫张小白。6 小时前
Vue3计算属性:高效数据处理
前端·javascript·vue.js·前端框架·vue
e***74956 小时前
【JavaEE】Spring Web MVC
前端·spring·java-ee
AntBlack7 小时前
Z-Image 发布了 ,赶紧体验了一把(配套 Modal执行脚本)
前端·后端·aigc