【发布时间】:2019-06-26 17:24:29
【问题描述】:
我创建了一个滑动输入。当用户激活按钮时,它会转到另一个视图并返回到按钮的视图,它没有被按下。 我需要按钮来保持状态。
我使用了 ng-modal 指令,并从控制器执行 $ scope.attributebutton = true;但它不起作用
input.vpn[type="checkbox"]{
-webkit-appearance: none;
-moz-appearance: none;
-webkit-transition: 400ms all;
transition: 400ms all;
margin: 0 auto 0 auto;
display: block;
border-radius: 50px;
background: #c4003b;
box-shadow: inset 0 0 0 2px rgba(0,0,0,.1);
width: 56px;
height: 26px;
outline: 0;
cursor: pointer;
position: relative;
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
animation: input 4s;
}
input.vpn[type="checkbox"]:checked, input.vpn[type="checkbox"].checked {
background: #60c674;
box-shadow: inset 0 0 0 10px #6ABF76;
transition: 250ms all;
}
input.vpn[type="checkbox"]::before {
content:'';
transition: 300ms all;
position: absolute;
left: 2px;
top: 2px;
bottom: 2px;
right: auto;
transform: translate(0,0);
display: block;
width: 32px;
height: 22px;
border-radius: 40px;
background: #FFFFFF;
box-shadow: 0 0 12px 0 rgba(0,0,0,0.06), 0 0 0 0 rgba(0,0,0,0.06), 0 6px 10px 0 rgba(0,0,0,0.15), 0 0 2px 0 rgba(0,0,0,0.07), 0 4px 6px 0 rgba(0,0,0,0.06), 0 1px 1px 0 rgba(0,0,0,0.11);
animation: button 3s ease-out;
}
input.vpn[type="checkbox"]:checked::before, input.vpn[type="checkbox"].checked::before{
transform: translate(20px,0);
}
<div class='col-md-6'>
<div ng-if="error.network.status=='success'">
<h2>
<span class="pull-right">
<input type="checkbox" class="vpn" ng-model="vm.activo" ng-click='changeVpn()'>
</span>
VPN
</h2>
</div>
</div>
【问题讨论】:
-
当您拥有的是切换样式的复选框时,您正在谈论“滑动输入”或按钮,因此您想要的是要选中的复选框。我看到它通过
ng-model链接到vm.active。如果它被修改,你必须通过将它们存储在数据库中或至少在 localStorage 中来使更改持久化,例如 -
您需要将按钮的状态存储在数据库或 sessionStorage 或 localStorage 中
-
请使用您的控制器代码更新。
标签: javascript html css angularjs