How to create an on/off switch with Javascript/CSS?

前端 未结 7 466
长情又很酷
长情又很酷 2020-12-04 09:41

I want to have a sliding switch. On the left would be Off and on the right would be On. When the user toggles the switch, I want the \'slider\' portion to slide to the other

7条回答
  •  情歌与酒
    2020-12-04 09:52

    Initial answer from 2013

    If you don't mind something related to Bootstrap, an excellent (unofficial) Bootstrap Switch is available.

    It uses radio types or checkboxes as switches. A type attribute has been added since V.1.8.

    Source code is available on Github.

    Note from 2018

    I would not recommend to use those kind of old Switch buttons now, as they always seemed to suffer of usability issues as pointed by many people.

    Please consider having a look at modern Switches like those.

提交回复
热议问题