switch滑动开关
<!DOCTYPE html>
<html>
<head >
<meta charset="utf-8">
<title></title>
<style type="text/css">
/*
使用:
1、html:修改input id和label for onclick="test1()"
2、css:修改#switch1:checked~label:before名字
修改#switch1:checked~label名字
3、js:函数名字 改按钮大小
1、改switch-container的宽高
2、改label:before的宽为switch-container的宽
3、改#switch:checked~label:before的left为switch-container的宽
*/ /* 开关的大小*/
.switch-container{
height: 24px;
width:48px; }
/*设置checkbox不显示*/
.switch{
display: none;
}
/*设置label标签为椭圆状*/
.switch-container label{
display: block;
background-color: #eee;
height: 100%;
width: 100%;
cursor: pointer;
border-radius: 25px;
position: relative;
}
/*在label标签内容之前添加如下样式,形成一个未选中状态*/
.switch-container label:before {
content: '';
display: block;
border-radius: 25px;
height: 100%;
width: 24px;
background-color: white;
position: absolute;
left: 0px;
box-shadow: 1px 1px 1px 1px rgba(0, 0, 0, 0.08);
-webkit-transition: all 0.5s ease;
transition: all 0.5s ease;
} /*选中后,未选中样式消失*/
#switch:checked~label:before {
left: 24px;
} /*选中后label的背景色改变*/
#switch:checked~label {
background-color: #4dbd74;
} /*选中后,未选中样式消失*/
#switch1:checked~label:before {
left: 24px;
} /*选中后label的背景色改变*/
#switch1:checked~label {
background-color: #4dbd74;
} </style> </head>
<body>
<div class="switch-container ">
<input type="checkbox" id="switch" class="switch">
<label for="switch" onclick="test()"></label>
</div> <div class="switch-box" style="width: 100px;">
<div class="switch-container " style="float: left;">
<input type="checkbox" id="switch1" class="switch">
<label for="switch1" onclick="test1()"></label>
</div>
<div style="float: right;">
<span id="switch1Con">选中</span>
</div>
</div> <script>
var test = function(){
console.log(!document.getElementById('switch').checked ? "选中" : "未选中");
}
var test1 = function(){
if (!document.getElementById('switch1').checked ) {
document.getElementById('switch1Con').innerHTML="开启";
}else{
document.getElementById('switch1Con').innerHTML="开启";
} }
</script>
</body>
</html>
switch滑动开关的更多相关文章
- android widgets控件
1.TextView 类似,C#里的lable,显示一段文本 <TextView android:id="@+id/textView2" android:layout_wid ...
- 【转】Android SwitchButton(滑动开关)
原文网址:http://blog.csdn.net/wangjinyu501/article/details/27961303 版本:1.0 日期:2014.5.17 2014.6.1 版权:© 20 ...
- Android SwitchButton(滑动开关)
@RemoteView public class Button extends TextView { public Button(Context context) { this(context, nu ...
- 自定义控件(视图)2期笔记05:自定义控件之继承自View(滑动开关)
1. 开关按钮点击效果,如下: 2. 继承已有View实现自定义View 3. 下面通过一个案例实现滑动开关的案例: (1)新建一个新的Android工程,命名为" 开关按钮", ...
- SlipButton——滑动开关
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjI1MjUwMg==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- Android实现Material Design风格的设置页面(滑动开关控件)
前言 本文链接 http://blog.csdn.net/never_cxb/article/details/50763271 转载请注明出处 參考了这篇文章 Material Design 风格的设 ...
- android自定义控件——以滑动开关为例
0.引言 (1)Android从4.0开始提供了switch的滑动开关效果组件,但是之前版本却没有 (2)很多时候我们写程序,都希望把有用的通用的通用的东西封装起来,以便以后重用. 本文根据组件开发思 ...
- Partition:分区切换(Switch)
在SQL Server中,对超级大表做数据归档,使用select和delete命令是十分耗费CPU时间和Disk空间的,SQL Server必须记录相应数量的事务日志,而使用switch操作归档分区表 ...
- java中if和switch哪个效率快
首先要看一个问题,if 语句适用范围比较广,只要是 boolean 表达式都可以用 if 判断:而 switch 只能对基本类型进行数值比较.两者的可比性就仅限在两个基本类型比较的范围内.说到基本类型 ...
随机推荐
- 微软职位内部推荐-Senior Software Engineer II-Sharepoint
微软近期Open的职位: SharePoint is a multi-billion dollar enterprise business that has grown from an on-prem ...
- Base64编码图片存取与前台显示
需求:将Base64编码图片以BLOB类型存入数据库,需要时取出显示 后台: String base64str=new String(log.getRequest_imgdata());//log为实 ...
- Scrum立会报告+燃尽图 04
此作业要求参见https://edu.cnblogs.com/campus/nenu/2018fall/homework/2194 一.小组介绍 组长:王一可 组员:范靖旋,王硕,赵佳璐,范洪达,祁玉 ...
- 1.12Linux下软件安装(学习过程)
实验介绍 介绍 Ubuntu 下软件安装的几种方式,及 apt,dpkg 工具的使用. 一.Linux 上的软件安装 通常 Linux 上的软件安装主要有三种方式: 在线安装 从磁盘安装deb软件包 ...
- Java中的静态变量static
package com.wangcf; public class Test { String name="你好"; static String sex="男"; ...
- “我爱淘”第二冲刺阶段Scrum站立会议4
完成任务: 完成了首页中的推荐功能,推荐的是最近添加的需要卖的书,注册功能实现了它,可以对数据库进行添加. 计划任务: 在客户端实现分类功能,通过学院的分类查看书籍. 遇到问题: 分类功能,根据不同学 ...
- HDU 5269 ZYB loves Xor I Trie树
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5269 bc:http://bestcoder.hdu.edu.cn/contests/con ...
- 给新建的kvm虚拟机创建网络接口
(一)首先必须创建网卡连接桥接口的启动脚本和停止脚本,其中脚本中的 $1:表示为虚拟机的网卡的右边接口,这两个脚本就是讲虚拟机的网卡的右边接口接在网桥上,实现桥接模型 # 1:/etc/qem ...
- 【beta】Scrum站立会议第6次....11.8
小组名称:nice! 组长:李权 成员:于淼 刘芳芳韩媛媛 宫丽君 项目内容:约跑app(约吧) 时间:2016.11.8 12:00——12:30 地点:传媒西楼220室 本次对beta阶段 ...
- eclipse错误:Access restriction: The type 'BASE64Decoder' is not API
Access restriction: The type ‘BASE64Decoder’ is not API (restriction on required library ‘D:\java\jd ...