Authored by 陈轩

switch button

@@ -86,6 +86,19 @@ iconfont 新建项目,使用 class 控制图标样式,不要用 unicode<br> @@ -86,6 +86,19 @@ iconfont 新建项目,使用 class 控制图标样式,不要用 unicode<br>
86 <input type="checkbox" id="switch1"> 86 <input type="checkbox" id="switch1">
87 <label for="switch1"></label> 87 <label for="switch1"></label>
88 </div> 88 </div>
  89 +<div class="switch">
  90 + <input type="checkbox" id="switch2" checked>
  91 + <label for="switch2"></label>
  92 +</div>
  93 +<div class="switch">
  94 + <input type="checkbox" id="switch3" disabled>
  95 + <label for="switch3"></label>
  96 +</div>
  97 +<div class="switch">
  98 + <input type="checkbox" id="switch4" checked disabled>
  99 + <label for="switch4"></label>
  100 +</div>
  101 +<br>
89 102
90 103
91 104
@@ -76,19 +76,44 @@ @@ -76,19 +76,44 @@
76 display: inline-block; 76 display: inline-block;
77 input { 77 input {
78 display: none; 78 display: none;
  79 + &:checked ~ label {
  80 + border: 2px solid #4bd865;
  81 + box-shadow: inset 0 0 0 calc(19px) #4bd865;
  82 + }
  83 + &:checked ~ label:after {
  84 + left: calc(54px - 34px);
  85 + box-shadow: 0 5px 5px -1px rgba(0, 0, 0, 0.2), 0 0 0 2px #4bd865;
  86 + }
  87 +
  88 + &:disabled ~ label {
  89 + opacity: 0.6;
  90 + }
  91 + &:disabled:checked ~ label {
  92 + opacity: 0.6;
  93 + }
  94 +
79 } 95 }
80 label { 96 label {
81 position: relative; 97 position: relative;
82 - display: block; 98 + display: inline-block;
83 width: 54px; 99 width: 54px;
84 height: 34px; 100 height: 34px;
85 background-color: $white; 101 background-color: $white;
86 - border: 1px solid #ddd; 102 + border: 2px solid #ddd;
87 border-radius: 99999px; 103 border-radius: 99999px;
88 transition: 0.3s; 104 transition: 0.3s;
89 105
90 &:after { 106 &:after {
91 content: ""; 107 content: "";
  108 + position: absolute;
  109 + left: 0;
  110 + width: 30px;
  111 + height: 30px;
  112 + border: none;
  113 + border-radius: 50%;
  114 + background-color: $white;
  115 + box-shadow: 0 5px 5px -1px rgba(0, 0, 0, 0.2), 0 0 0 2px #ddd;
  116 + transition: 0.3s;
92 } 117 }
93 } 118 }
94 } 119 }