Cod*_*Man 5 html javascript css twitter-bootstrap angular
需要实现类似于所附图像的开关按钮......
安装npm install ngx-toggle-switch --save
用法:-
import { UiSwitchModule } from 'ngx-toggle-switch';
import { AppComponent } from './app.component';
@NgModule({
imports: [BrowserModule, UiSwitchModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {
}
Run Code Online (Sandbox Code Playgroud)
在标记语言中:-
<ui-switch></ui-switch>
Run Code Online (Sandbox Code Playgroud)
对于双向绑定
<ui-switch [(ngModel)]="enable"></ui-switch>
Run Code Online (Sandbox Code Playgroud)
有关 Packge 的文档,请参阅:- ngx-toggle-switch
您可以使用普通复选框和一些 css 来获得该功能。下面是有帮助的代码。
CSS:
.switch {
position: relative;
display: inline-block;
width: 45px;
height: 20px;
margin: 20px;
}
.switch input {display:none; background-color: #ccc;}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 0px;
right: 0px;
bottom: -3px;
background-color: #2196F3;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider:before {
-webkit-transform: translateX(20px);
-ms-transform: translateX(20px);
transform: translateX(20px);
}
/* Rounded sliders */
.slider.round {
border-radius: 20px;
}
.slider.round:before {
border-radius: 50%;
}
Run Code Online (Sandbox Code Playgroud)
网页:
<div class="row">
<label>Yes</label>
<label class="switch">
<input type="checkbox" [(ngModel)]="isNewProfile">
<span class="slider round"></span>
</label>
<label>No</label>
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25067 次 |
| 最近记录: |