当前位置:网站首页>Use (offset, page) in JS to achieve login effect
Use (offset, page) in JS to achieve login effect
2022-07-19 05:11:00 【Create splendid -- hand in hand with you】
css The content part :
*{
padding: 0px;
margin: 0px;
}
li{
list-style: none;
}
a{
text-decoration: none;
}
.bg{
width: 100%;
height: 100%;
position: fixed;
top: 0px;
left:0px;
background: rgb(0,0,0,.4);
z-index: 9998;
display: none;
}
.login{
width: 600px;
height: 300px;
position: fixed;
top:50%;
left:50%;
/* Place the login interface in the center of the browser */
transform: translate(-50%,-50%);
z-index: 9999;
background: #fff;
/* The style of the mouse inside the login interface */
display: none;
}
.title{
height: 45px;
line-height: 45px;
text-align: center;
border-bottom: 1px solid #DCDCDC;
position: relative;
cursor: move;
}
.content p{
text-align: center;
line-height: 45px;
}
.title a{
display: block;
position: fixed;
top:2px;
right: 5px;
z-index: 9999;
}HTML The content part :
<!-- Make a login box -->
<a href="javascript:;" id="loginA"> register / Sign in </a>
<!-- Login pop-up -->
<div class="login">
<div class="title">
The user login <a href="javascript:;" id="close"> close </a>
</div>
<div class="content">
<p> user name :<input type="text" value="" /></p>
<p> password :<input type="password" value="" /></p>
<p> <input type="button" value=" Submit " /></p>
</div>
</div>
<div class="bg"></div>js The content part : ( Detailed introduction )
notes : Red refers to getting the element part , Green refers to the display login section , Blue refers to the hidden part , Orange refers to the main implementation content . The black part is the annotation part .
// Get elements
var title=document.querySelector('.title');
var loginA=document.getElementById('loginA');
var login=document.querySelector('.login');
var close=document.getElementById('close');
var bg=document.querySelector('.bg');
// Show login box
loginA.οnclick=function(){
login.style.display='block';
bg.style.display='block';
}
// Hide login box
close.οnclick=function(){
login.style.display='none';
bg.style.display='none';
}
// Mobile login box , Only in title Move the box within the range
// The mouse movement event attribute is (mousedown)
// Set listening events
title.addEventListener('mousedown',function(e){
// var x=e.pageX-login.offsetLeft;
// var y=e.pageY-login.offsetTop;
// console.log(x,y);
// In this way, a negative value will appear when printed , The reason is that the above css In the animation
//transform, The value it subtracts is calculated according to the original position , The solution is , In the formula above
// Then subtract the general width and height of the frame , Write the value directly , Note above , The correct writing is below ;
var x=e.pageX-(login.offsetLeft-300);
var y=e.pageY-(login.offsetTop-150);
// When calculating mouse movement , The distance the login box needs to move
// Here, the mouse is moved in , And call the function in the listening event
document.addEventListener('mousemove',move);
function move(e){
// Calculated value
var newX=e.pageX-x;
var newY=e.pageY-y;
// Because the left side of the box is added above , Upper value , You can no longer add , The main reason is that the upper minus value , If the original minus value is not added to the bottom , The position of the mouse is in the lower right corner of the frame
// Not where we want to achieve .
login.style.left=newX+300+"px";
login.style.top=newY+150+"px";
}
// eliminate mousemove Mobile event
document.addEventListener('mouseup',function(){
// Clear the functions in the mouse move move
document.removeEventListener('mousemove',move);
})
})
Main effects :

边栏推荐
- Installation and fast use of Mongo DB stand-alone version
- SQL statement learning
- mysql数据库实验实训6,数据视图(详细)
- User login - and create SMS verification code
- 使用js中的(offset,page)实现登录效果
- 小程序editor富文本编辑使用及rich-text解析富文本
- 02 Bar _ Recommandation de film (basée sur le contenu) Portrait de l'utilisateur
- 游玩数据获取与数据分析、数据挖掘 【2022.5.30】
- 小程序云开发 上传图片到云存储
- 【C语言—零基础第十一课】旋转大转盘之指针
猜你喜欢

mysql数据库实验实训5,数据查询yggl数据库查询(详细)

C语言初学者之初识代码专项练习

Use of flask

小程序editor富文本编辑使用及rich-text解析富文本

ModerlArts第一次培训笔记

使用Echars实现水滴状、环形图、分割图、堆叠、组织架构图、地图轮廓等图表

Harmonyos third training notes
![[2022 10th Teddy Cup Challenge] Title A: complete version of pest identification (general idea. Detailed process and code and results CSV in compressed package)](/img/e6/beea0bb0a9f4b41206c6fcb130fdfd.png)
[2022 10th Teddy Cup Challenge] Title A: complete version of pest identification (general idea. Detailed process and code and results CSV in compressed package)

机器学习之PCA特征降维+案例实践

es6新增-运算符的扩展
随机推荐
机器学习之特征提取(类别特征进行数值化、离散化、文本特征进行数值化)
es6新增-运算符的扩展
C语言 带你 手撕 通讯录
Topicexchange switch is simple to use.
【C语言—零基础第十一课】旋转大转盘之指针
Baidu map realizes thermal map
STL容器——queue与deque的基本操作
[p5.js] simulated fireworks effect - interactive media design assignment
Installation and fast use of Mongo DB stand-alone version
百度地图 实现 热力图
02_电影推荐(ContentBased)_用户画像
Getting started with harmonios
PAT乙级1017: A除以B
轮播图的两种方法及自动轮播
硬核结构体,暴力解读
MD5 password encryption
Applet cloud development form submission and data acquisition in the page
数据分析与数据挖掘实战案例本地房价预测(716):
Mysql database experiment training 6, data view (detailed)
Uni app conditional compilation ifdef ENDIF compatible with multiple terminals