5.用 CSS 创作一个立体滑动 toggle 交互控件
原文地址:https://segmentfault.com/a/1190000014638655
HTML代码:
<html>
<head>
<link rel="stylesheet" href="index.css">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<body>
<div class="checkbox">
<div class="inner">
<div class="toggle"></div>
</div>
</div>
<script src="index.pack.js"></script>
</body>
</html>
CSS代码:
/* */
/* 居中显示: */
html,
body,
.checkbox,
.checkbox .inner,
.checkbox .inner .toggle {
margin:;
padding:;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
/* 画出外侧椭圆: */
.checkbox {
width: 10em;
height: 5em;
background: linear-gradient(silver, whitesmoke);
border-radius: 2.5em;
font-size: 30px;
}
/* 画出内侧椭圆 */
.checkbox .inner {
width: 8em;
height: 3.5em;
background: linear-gradient(dimgray, silver);
border-radius: 2em;
box-shadow: inset 0 0 1.5em rgba(0, 0, 0, 0.5);
}
/* 画出圆形按钮: */
.checkbox .inner .toggle {
width: 3.5em;
height: 3.5em;
background: linear-gradient(to top, silver, whitesmoke);
border-radius: 50%;
box-shadow: 0 0.4em 0.6em rgba(0, 0, 0, 0.2);
position: relative;
left: -30%;
}
/* 为圆形按钮增加立体效果: */
.checkbox .inner .toggle::before {
content: 'OFF';
position: absolute;
width: 80%;
height: 80%;
background: linear-gradient(silver, whitesmoke);
border-radius: 50%;
text-align: center;
line-height: calc(3.5em * 0.8);
font-family: sans-serif;
color: gray;
} /* 设置 active 时控件的样式: */
.checkbox .inner.active {
background: linear-gradient(green, limegreen);
}
.checkbox .inner.active .toggle {
left: 30%;
}
.checkbox .inner.active .toggle::before {
content: 'ON';
color: limegreen;
}
JS代码:
$(document).ready(function() {
$('.toggle').click(function() {
$('.inner').toggleClass('active');
});
});
5.用 CSS 创作一个立体滑动 toggle 交互控件的更多相关文章
- 如何用 CSS 创作一个立体滑动 toggle 交互控件
效果预览 在线演示 按下右侧的"点击预览"按钮在当前页面预览,点击链接全屏预览. https://codepen.io/zhang-ou/pen/zjoOgX 可交互视频教程 此视 ...
- 1.纯 CSS 创作一个按钮文字滑动特效 + 弹幕(残缺)
原文地址:1# 视频演示如何用纯 CSS 创作一个按钮文字滑动特效 扩展后地址:https://scrimba.com/c/cJkzMfd HTML代码: <html> <head& ...
- 3.纯 CSS 创作一个容器厚条纹边框特效
原文地址:3.纯 CSS 创作一个容器厚条纹边框特效 没有啥好点子呀,不爽 HTML代码: <div class="box"> <div class=" ...
- 2.纯 CSS 创作一个矩形旋转 loader 特效
原文地址:2.纯 CSS 创作一个矩形旋转 loader 特效 扩展后地址:https://scrimba.com/c/cNJVWUR 扩展地址:https://codepen.io/pen/ HT ...
- 一个Activity掌握Design新控件 (转)
原文地址:http://blog.csdn.net/lavor_zl/article/details/51295364 谷歌在推出Android5.0的同时推出了全新的设计Material Desig ...
- 一个Bootstrap风格的分页控件
http://www.cnblogs.com/wangwei123/p/3682626.html 主题 jQueryBootstrap 一个Bootstrap风格的分页控件,对于喜欢Bootstr ...
- ArcGIS“一个或多个ActiveX控件无法显示...”问题的解决方案
ArcMap启动时的一个警告信息“一个或多个ActiveX控件无法显示...”,如图 出现这种情况,有可能的原因是IE浏览器的安全选项设置被修改了.比如被手动修改过,或者被第三方系统杀毒优化软件修改了 ...
- 创建一个带模版的用户控件 V.3
再重构此篇<创建一个带模版的用户控件 V.2>http://www.cnblogs.com/insus/p/4164149.html 让其它动态实现header,Item和Footer. ...
- 创建一个带模版的用户控件 V.2
前面有做练习<创建一个带模版的用户控件>http://www.cnblogs.com/insus/p/4161544.html .过于简化.通常使用数据控件Repeater会有网页写好He ...
随机推荐
- Mongodb $setOnInsert操作符 和upsert:true
upsert:true:如果要更新的文档不存在的话会插入一条新的记录 $setOnInsert操作符会将指定的值赋值给指定的字段,如果要更新的文档存在那么$setOnInsert操作符不做任何处理: ...
- 谈ObjC对象的两段构造模式
前言 Objective-c语言在申请对象的时,需要使用两段构造(Two Stage Creation)的模式.一个对象的创建,需要先调用alloc方法或allocWithZone方法,再调用init ...
- JPEG文件格式
格式:JFIF(JPEG档的交换格式)压缩:JPEG(灰阶影像压缩比约为10:1:彩色影像约为20:1)以JPEG文件格式保存的图像实际上是2个不同格式的混合物:JPEG格式规范本身,用来定义图像的压 ...
- FabricExpress.net supply high quality quilting fabric
FabricExpress is a company specializing in high quality custom t-shirts,custom fabric,senior handmad ...
- Select2 用法
http://www.cnblogs.com/wuhuacong/p/4761637.html 2.这个做详细参考 http://www.jianshu.com/p/c5ab74b91b2e 3.ht ...
- Ribbon Control
https://documentation.devexpress.com/#WindowsForms/CustomDocument2492 The Ribbon Control replaces tr ...
- PHP的extension_dir设置问题
PHP安装时,extension_dir的路径要设成绝对路径:extension_dir = "D:/Tools/php-7.0.5/ext", 不然如果设成extension_d ...
- python之 序列与字典遍历
在Python中有六种内建的序列:列表.元组.字符串.Unicode字符串.buffer对象和xrange对象.在这里暂时只讨论字符串.列表和元组的遍历. 一. 序列遍历 序列有两种遍历:一种通过值 ...
- ORA-10997:another startup/shutdown operation of this instance in progress解决方法
SQL> startup ORA-10997: another startup/shutdown operation of this instance inprogress ORA-09967: ...
- 分布式数据存储 shard(切片) 和 repali(副本) 的 节点数的关系。
1 , node 的 数量 应该大于等于 副本(指的是单个 shard 的 主副本+备份副本数)的 数量 ,如果 副本的数量大于 node 数量,那么 一个node 必定有2 个相同的 副本,这个多出 ...