如何用Javascript / CSS创建一个开/关切换? [英] How to create an on/off switch with Javascript/CSS?
本文介绍了如何用Javascript / CSS创建一个开/关切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想有一个滑动开关。在左边是关闭,右边是打开。当用户切换开关时,我想要'滑块'部分滑动到另一侧并指示它关闭。
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 side and indicate it is off. I could then have a callback that takes as input the state of the toggle switch so I can act accordingly.
任何想法如何做到这一点?
Any idea how to do this?
推荐答案
你的意思是像iPhone的复选框?
尝试 Thomas Reynolds的iOS复选框脚本:
You mean something like IPhone checkboxes? Try Thomas Reynolds' iOS Checkboxes script:
文件可供您的网站使用后,激活脚本非常简单:
Once the files are available to your site, activating the script is very easy:
...
$(document).ready(function() {
$(':checkbox').iphoneStyle();
});
结果:
这篇关于如何用Javascript / CSS创建一个开/关切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文