简体   繁体   English

如何使HTTP / CSS复选框滑块正常工作?

[英]How to make an HTTP/CSS Checkbox Slider to work properly?

I'll be glad if you can help me. 如果你能帮助我,我会很高兴的。 I was required to develop a checkbox slider. 我被要求开发一个复选框滑块。

The issue is that when I click on the Slider I need that 2 things will happen: 问题是,当我点击滑块时,我需要做两件事:

  1. When the slider block is on left, the "Specific" word will be hidden and will be shown only after clicking the block which will turn to the right side. 当滑块位于左侧时,“特定”字将被隐藏,并且仅在单击将转向右侧的块后才会显示。

  2. That the sliding will be in an animation. 滑动将在动画中。

Here's the code: 这是代码:

HTML:
=====
<div class="checkboxThree">
   <input type="checkbox" value="0" id="checkboxThreeInput" name="" />
   <label for="checkboxThreeInput"></label>
</div>

CSS:
====
/**
 * Checkbox Three
 */
.checkboxThree {
    width: 95px;
    height: 16px;
    background:#A22452;
    border-radius: 50px;
    position: relative;
    margin:0 auto;
    margin-top: 5px;
}

    /**
     * Create the text for the "All" position
     */
    .checkboxThree:before {
      content: 'All';
      position: absolute;
      top: -1px;
      left: 70px;
      height: 2px;
      color: #F9F9F9;
      font-size: 14px;
      font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
      font-weight: bold;
    }

    /**
     * Create the label for the "Specific" position
     */
    .checkboxThree:after {
       content: 'Specific';
       position: absolute;
       top: -1px;
       left: 4px;
       height: 2px;
       color: #F7A6F4;
       font-size: 14px;
       font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
       font-weight: bold;
    }

    /**
     * Create the pill to click
     */
    .checkboxThree label {
        display: block;
        width: 32px;
        height: 14px;
        border-radius: 50px;
        transition: all .5s ease;
        cursor: pointer;
        position: absolute;
        top: 1px;
        z-index: 1;
        /* left: 12px; */
        background: #08EFEF;

    }

    /**
     * Create the checkbox event for the label
     */
    .checkboxThree input[type=checkbox]:checked + label {
        left: 62px;

    }

link: https://jsfiddle.net/gtq792sa/

Can you please show me how to fix it ? 你能告诉我如何解决它吗?

here is a nice answer. 是一个很好的答案。 It comes down to having a label with an input type="slider" inside it, and lots of css styling. 它归结为一个带有输入类型=“滑块”的标签,以及大量的CSS样式。

You should probably use an existing slider like Bootstrap Switch 你应该使用像Bootstrap Switch这样的现有滑块

It's an unofficial component for bootstrap made by the community. 这是社区制作的bootstrap的非官方组件。 And I think you can use it without bootstrap. 而且我认为你可以在没有bootstrap的情况下使用它。

Anyway, in general the easiest way to do this kind of stuff is using Javascript, this allow you to easily check your chexbox, retrieve information on it and animate your button. 无论如何,一般来说,最简单的方法就是使用Javascript,这样您就可以轻松检查chexbox,检索chexbox上的信息并为按钮设置动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM