H5模拟IOS端switch按钮

image

H5 模拟 IOS 端 switch 滑动按钮样式

css 代码

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
.switch {
display: block;
position: relative;
width: 1.1rem;
height: 0.7rem;
border: 1px solid #dedede;
outline: 0;
border-radius: 0.35rem;
box-sizing: border-box;
background-color: #f2f2f2;
transition: background-color 0.1s, border 0.1s;
cursor: pointer;
float: right;
top: 0.2rem;
}
.switch:before {
content: " ";
position: absolute;
transition: transform 0.35s cubic-bezier(0.45, 1, 0.4, 1);
}
.switch:after {
content: " ";
position: absolute;
top: 0.02rem;
width: 0.6rem;
height: 0.6rem;
border-radius: 0.3rem;
background-color: #FFFFFF;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
transition: transform 0.35s cubic-bezier(0.4, 0.4, 0.25, 1.35);
}
.switch-on {
border-color: green;
background-color: green;
}
.switch-on:before {
border-color: green;
background-color: green;
}
.switch-on:after {
transform: translateX(0.45rem);
}

html 使用

1
<span class="swtich"></span>

效果

image

咸鱼也要有梦想,万一实现了呢
0%