Home > front end >  Why the console. The log (login. OffsetLeft); Output is not the most on the left side of the box lef
Why the console. The log (login. OffsetLeft); Output is not the most on the left side of the box lef

Time:12-20




<meta charset="utf-8" & gt;

<style>
. The login - the header {
width: 100%;
text-align: center;
height: 30px;
The font - size: 24 px;
The line - height: 30 px;
}

Ul,
Li,
Ol,
Dl,
Dt,
Dd,
Div,
P
Span,
H1,
H2,
H3,
H4,
The h5,
H6,
A {
padding: 0px;
margin: 0px;
}

The login {
display: none;
Width: 512 px;
Height: 280 px;
position: fixed;
Border: # ebebeb solid 1 px;
left: 50%;
top: 50%;
Background: # FFFFFF;
Box - shadow: 0 px 0 px 20 px # DDD;
Z - index: 9999;
transform: translate(-50%, -50%);
}

. The login - the title {
width: 100%;
10 px margin: 0 px 0 px 0 px;
text-align: center;
line-height: 40px;
height: 40px;
The font - size: 18 px;
position: relative;
Cursor: move;
}

. The login - input - content {
Margin - top: 20 px;
}

. The login - the button {
Width: 50%;
30 px auto margin: 0 px auto;
line-height: 40px;
The font - size: 14 px;
Border: # 1 px solid ebebeb;
text-align: center;
}

. The login - bg {
display: none;
width: 100%;
height: 100%;
position: fixed;
Top: 0 px;
left: 0px;
Background: rgba (0, 0, 0, 3);
}

A {
text-decoration: none;
Color: # 000000;
}

Login - button a {
display: block;
}

. The login - input input. The list - input {
float: left;
The line - height: 35 px;
Height: 35 px;
Width: 350 px;
Border: # 1 px solid ebebeb;
The text text-indent: 5 px;
}

. The login - input {
overflow: hidden;
Margin: 0 px 0 px 20 px 0 px;
}

. The login - input label {
float: left;
Width: 90 px;
Padding - right: 10 px;
The text - align: right;
The line - height: 35 px;
Height: 35 px;
The font - size: 14 px;
}

. The login - the title span {
position: absolute;
font-size: 12px;
Right: - 20 px;
Top: - 30 px;
Background: # FFFFFF;
Border: # ebebeb solid 1 px;
Width: 40 px;
height: 40px;
border-radius: 20px;
}
</style>


<body>



<script>
//1. Get element
Var login=document. QuerySelector (' login ');
Var mask=document. QuerySelector (' login - bg ');
Var link=document. QuerySelector (' # link ');
Var closeBtn=document. QuerySelector (' # closeBtn ');
Var title=document. QuerySelector (' # title);
//2. Click on this link to pop up layer mask and display the login
Link. AddEventListener (' click ', function () {
='block' mask. Style. The display;
='block' login. Style. The display;
})
//3. Click closeBtn hidden mask and login
CloseBtn. AddEventListener (' click ', function () {
Mask. Style. The display='none';
The login. Style. The display='none';
})
//4. Began to drag
//(1) when we press the mouse, to get the coordinates of the mouse within the box
Title. The addEventListener (' mousedown ', function (e) {
Var x=e.p ageX - login. OffsetLeft;
Var y=e.p ageY excuse - login. OffsetTop;
The console. The log (e.p ageX);
The console. The log (login. OffsetLeft);
//(2) when the mouse moves, the coordinates of the mouse on the page, minus the coordinates of the mouse within the box is left and top value of the modal dialog
Document. The addEventListener (' mousemove 'move)

The function move (e) {
The login. Style. Left=e.p ageX - x + 'px';
The login. The style. The top=e.p ageY excuse - y + 'px';
}
//(3) the mouse bounces, let the mouse events to remove
Document. The addEventListener (" mouseup ", function () {
Document. The removeEventListener (' mousemove 'move);
})
})
</script>


  • Related