滑动登录界面
实现的是登录与注册之间相互切换,背景也会跟着改变的效果
body {
background-color: #ededed;
display: flex;
width: 100vw;
height: 100vh;
overflow: hidden;
}
.flexCenter {
display: flex;
align-items: center;
justify-content: center;
}
.main {
position: relative;
width: 900px;
height: 550px;
margin: auto;
overflow: hidden;
border: 1px solid #ccc;
}
.switchWrapper {
position: absolute;
z-index: 99;
left: 0;
overflow: hidden;
width: 32%;
height: 100%;
background-color: rgba(255, 255, 255, 0.4);
transition: transform 1s ease-in-out;
}
/* 背景跟随滚动 */
.switchWrapper::after {
content: '';
display: block;
background-image: url('./pc.png');
background-size: 900px 550px;
background-position: top left;
width: 100%;
height: 100%;
overflow: hidden;
transition: all 1s ease-in-out;
}
.active .switchWrapper::after {
background-position: top right;
}
/* 背景跟随滚动 end*/
.btn {
position: absolute;
width: 90px;
height: 36px;
color: #fffffe;
background-color: #ff8906;
font-size: 15px;
border-radius: 30px;
cursor: pointer;
flex-wrap: wrap;
overflow: hidden;
}
.active .switchWrapper {
transform: translateX(calc(900px - 100%));
}
/* 垂直文字 */
.text {
width: 100%;
height: 100%;
transition: all 1s ease-in-out;
user-select: none;
}
.active .text:first-child {
margin-top: -100%;
}
/* 内容区 */
.outerBox {
position: absolute;
z-index: 9;
left: 32%;
overflow: hidden;
width: 68%;
height: 100%;
transition: all 1s ease-in-out;
}
.container {
width: 100%;
height: 100%;
background-color: #fffffe;
}
.active .outerBox {
transform: translateX(calc(-900px + 100%));
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<div class="main">
<!--功能区-->
<div class="switchWrapper flexCenter">
<div class="btn flexCenter">
<div class="text flexCenter">去登录</div>
<div class="text flexCenter">去注册</div>
</div>
</div>
<!-- 表单区域 -->
<div class="outerBox">
<div class="container flexCenter">
<div class="signInBox">
<div class="tips">注册内容区</div>
<div>
<input type="text">
</div>
<div>
<input type="text">
</div>
<button class="regLog">注册</button>
</div>
</div>
</div>
</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const main = document.querySelector('.main');
const btn = document.querySelector('.btn');
const signInBox = document.querySelector('.signInBox');
const tips = document.querySelector('.tips');
const regLogBtn = document.querySelector('.regLog');
btn.onclick = () => {
if (main.className.indexOf('active') != -1) {
main.className = 'main';
setTimeout(() => {
tips.innerText = '注册内容区';
regLogBtn.innerText = '注册';
}, 500);
} else {
main.className = 'main active';
setTimeout(() => {
tips.innerText = '登录内容区';
regLogBtn.innerText = '登录';
}, 500);
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
在线编辑 (opens new window)
上次更新: 2021/11/23, 15:19:29