This article mainly introduces how to use javascript and CSS to implement special effects of Apple switch buttons and all the code. The results are very good and the compatibility is also good. If you need them, refer to the effect of Apple switch buttons ~~
When disabled
Html
The Code is as follows:
Apple button
Css
The Code is as follows:
# P1 {
Width: 170px;
Height: 100px;
Border-radius: 50px;
Position: relative;
}
# P2 {
Width: 96px;
Height: 96px;
Border-radius: 48px;
Position: absolute;
Background: white;
Box-shadow: 0px 2px 4px rgba (0, 0, 0, 0.4 );
}
. Open1 {
Background: rgba (0,184, 0, 0.8 );
}
. Open2 {
Top: 2px;
Right: 1px;
}
. Close1 {
Background: rgba (255,255,255, 0.4 );
Border: 3px solid rgba (0, 0, 0, 0.15 );
Border-left: transparent;
}
. Close2 {
Left: 0px;
Top: 0px;
Border: 2px solid rgba (0.1, 0 );
}
Javascript
The Code is as follows:
Window. onload = function (){
Var p2 = document. getElementById ("p2 ");
Var p1 = document. getElementById ("p1 ");
P2.onclick = function (){
P1.className = (p1.className = "close1 ")? "Open1": "close1 ";
P2.className = (p2.className = "close2 ")? "Open2": "close2 ";
}
}
The above is all the content of this article, hoping to help you master the WEB Front-end design.