Proto.io Toggle Switch /复选框不会切换

时间:2014-06-20 15:12:23

标签: html css

尝试让切换开关工作,并且它拒绝切换,即使数据被剥离/未应用于输入(数据字段属性将数据应用于切换)。任何人都可以看到我没有的东西吗?所有切换都是使用proto.io CSS完成的。这是它的HTML:

         <h2 id="workflow-header" class="work-header"></h2>
    <div class="onoffswitch" id="workflow">
        <input type="checkbox" class="onoffswitch-checkbox" id="email-switch-thing" data-field="subscribeToWorkflowEmail" {{#if checked}}checked{{/if}}>
        <label class="onoffswitch-label" for="email-switch-thing">
            <div class="onoffswitch-inner" id="activeworkflow-toggle"></div>
            <div class="onoffswitch-switch"></div>
        </label>

    </div>

这是CSS:

.onoffswitch {
    position: relative; width: 90px;
    -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}

.onoffswitch-checkbox {
    display: none;
}

.onoffswitch-label {
    display: block; overflow: hidden; cursor: pointer;
    border: 2px solid #666666; border-radius: 30px;
}

.onoffswitch-inner {
    display: block; width: 200%; margin-left: -100%;
    -moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
    -o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}

.onoffswitch-inner:before, .onoffswitch-inner:after {
    display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
    font-size: 16px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
    -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
    border-radius: 30px;
    box-shadow: 0px 15px 0px rgba(0,0,0,0.08) inset;
}

.onoffswitch-inner:before {
    content: "ON";
    padding-left: 15px;
    background-color: #6BB2ED; color: #FFFFFF;
    border-radius: 30px 0 0 30px;
}

.onoffswitch-inner:after {
    content: "OFF";
    padding-right: 15px;
    background-color: #FFFFFF; color: #666666;
    text-align: right;
    border-radius: 0 30px 30px 0;
}

.onoffswitch-switch {
    display: block; width: 30px; margin: 0px;
    background: #FFFFFF;
    border: 2px solid #666666; border-radius: 30px;
    position: absolute; top: 0; bottom: 0; right: 56px;
    -moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
    -o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s; 
    background-image: -moz-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%); 
    background-image: -webkit-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%); 
    background-image: -o-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%); 
    background-image: linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
    box-shadow: 0 1px 1px white inset;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
    margin-left: 0;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
    right: 0px; 
}

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:2)

我不确定为什么它不适合你,但它对我有用。 Here我已将我用于解决问题的JSFiddle链接起来。

HTML:

     <h2 id="workflow-header" class="work-header"></h2>
<div class="onoffswitch" id="workflow">
    <input type="checkbox" class="onoffswitch-checkbox" id="email-switch-thing" data-field="subscribeToWorkflowEmail" {{#if checked}}checked{{/if}}>
    <label class="onoffswitch-label" for="email-switch-thing">
        <div class="onoffswitch-inner" id="activeworkflow-toggle"></div>
        <div class="onoffswitch-switch"></div>
    </label>

</div>

CSS:

.onoffswitch {
    position: relative; width: 90px;
    -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}

.onoffswitch-checkbox {
    display: none;
}

.onoffswitch-label {
    display: block; overflow: hidden; cursor: pointer;
    border: 2px solid #666666; border-radius: 30px;
}

.onoffswitch-inner {
    display: block; width: 200%; margin-left: -100%;
    -moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
    -o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}

.onoffswitch-inner:before, .onoffswitch-inner:after {
    display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
    font-size: 16px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
    -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
    border-radius: 30px;
    box-shadow: 0px 15px 0px rgba(0,0,0,0.08) inset;
}

.onoffswitch-inner:before {
    content: "ON";
    padding-left: 15px;
    background-color: #6BB2ED; color: #FFFFFF;
    border-radius: 30px 0 0 30px;
}

.onoffswitch-inner:after {
    content: "OFF";
    padding-right: 15px;
    background-color: #FFFFFF; color: #666666;
    text-align: right;
    border-radius: 0 30px 30px 0;
}

.onoffswitch-switch {
    display: block; width: 30px; margin: 0px;
    background: #FFFFFF;
    border: 2px solid #666666; border-radius: 30px;
    position: absolute; top: 0; bottom: 0; right: 56px;
    -moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
    -o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s; 
    background-image: -moz-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%); 
    background-image: -webkit-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%); 
    background-image: -o-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%); 
    background-image: linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
    box-shadow: 0 1px 1px white inset;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
    margin-left: 0;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
    right: 0px; 
}

研究,我能找到的唯一解决方案是,如果您使用IE8,它可能是一个兼容性问题,因为您需要启用它的支持 来源here。我对听起来很轶事犹豫不决,但是当我使用CSS按钮遇到类似的问题时,结果却是一个简单的兼容性/支持问题,这就是让我想到这一点的原因。

答案 1 :(得分:0)

我成功执行的步骤:

1)制作一个CSS文件(输入NeatoBandito共享的所有数据)命名为:newbtn.css

2)制作一个HTML文件(输入NeatoBandito共享的所有数据,记得包含链接href行,以便包含CSS文件)命名为:newbtn.html

3)执行HTML文件(在本地wamp服务器中,它将成功执行)

<link href="newbtn.css" rel="stylesheet">
  <h2 id="workflow-header" class="work-header"></h2>
<div class="onoffswitch" id="workflow">
    <input type="checkbox" class="onoffswitch-checkbox" id="email-switch-thing" data-field="subscribeToWorkflowEmail" {{#if checked}}checked{{/if}}>
    <label class="onoffswitch-label" for="email-switch-thing">
        <div class="onoffswitch-inner" id="activeworkflow-toggle"></div>
        <div class="onoffswitch-switch"></div>
    </label>

</div>

感谢阅读。