Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
.switch { --c-background-top: #75757D; --c-background-bottom: #45454C; --c-background-top-shadow: rgba(255, 255, 255, .45); --c-background-bottom-shadow: rgba(0, 0, 0, .3); --c-stroke-top: #262626; --c-stroke-bottom: #3D3D43; --c-inner: #6D6D6D; --c-inner-top-shadow: rgba(0, 0, 0, .3); --c-inner-bottom-shadow: rgba(255, 255, 255, .18); --c-inner-inset-shadow: rgba(0, 0, 0, .14); --c-knob-stroke-top: #515151; --c-knob-stroke-bottom: #acacac; --c-knob-inner-top: #8A8A8A; --c-knob-inner-middle-top: #A1A1A1; --c-knob-inner-middle-bottom: #B4B4B4; --c-knob-inner-bottom: #BABABA; --c-knob-inner-shadow-top: rgba(255, 255, 255, .25); --c-knob-inner-shadow-bottom: rgba(0, 0, 0, .3); --c-knob-shadow-1: rgba(7, 7, 37, 0.16); --knob-inner-shadow-top-y: 2.5px; --knob-inner-shadow-bottom-y: -5.5px; --knob-shadow-1-y: 20px; --knob-shadow-1-blur: 20px; --knob-shadow-1-spread: 0; --knob-shadow-2-y: 12.5px; --knob-shadow-2-blur: 8.5px; --knob-shadow-3-y: 6.5px; --knob-shadow-3-blur: 4.5px; --knob-shadow-4-y: 4px; --knob-shadow-4-blur: 2.5px; --knob-shadow-7-y: 15px; --top-shadow-blur: 5px; --inner-bottom-shadow-blur: 1.25px; --shine-top-opacity: 0; --shine-top-y: -5px; --shine-bottom-opacity: 1; --shine-bottom-y: 0px; -webkit-appearance: none; -webkit-tap-highlight-color: transparent; border: none; background: none; padding: 0; margin: 0; outline: none; position: relative; cursor: pointer; border-radius: 36px; box-shadow: 0 4px 2.5px rgba(0, 0, 0, 0.0525), 0 8px 4.5px rgba(0, 0, 0, 0.065), 0 12px 8px rgba(0, 0, 0, 0.17), 0 22.5px 14.5px rgba(0, 0, 0, 0.07), 0 35px 25px rgba(0, 0, 0, 0.08), 0 20px 15px rgba(0, 0, 0, 0.05); } .switch.active { --c-background-top: #F0F0F0; --c-background-bottom: #E9E9E9; --c-background-top-shadow: #fff; --c-background-bottom-shadow: rgba(0, 0, 0, .18); --c-stroke-top: #E7E7E7; --c-stroke-bottom: #D0D0D0; --c-inner: #EAEAEA; --c-inner-top-shadow: rgba(156, 56, 0, 0.42); --c-inner-bottom-shadow: #FFF3E5; --c-inner-inset-shadow: rgba(0, 0, 0, .2); --c-knob-stroke-top: #cc4528; --c-knob-stroke-bottom: #f05f21; --c-knob-inner-top: #E94714; --c-knob-inner-middle-top: #E85617; --c-knob-inner-middle-bottom: #FF7324; --c-knob-inner-bottom: #FF844F; --c-knob-inner-shadow-top: rgba(255, 170, 109, 0.45); --c-knob-inner-shadow-bottom: rgba(244, 44, 0, 0.9); --c-knob-shadow-1: rgba(255, 180, 175, 0.7); --knob-inner-shadow-top-y: 5.5px; --knob-inner-shadow-bottom-y: -1.5px; --knob-shadow-1-y: 0; --knob-shadow-1-blur: 2px; --knob-shadow-1-spread: 5px; --knob-shadow-2-y: 6.5px; --knob-shadow-2-blur: 4.5px; --knob-shadow-3-y: 3.5px; --knob-shadow-3-blur: 2.5px; --knob-shadow-4-y: 2px; --knob-shadow-4-blur: 1.5px; --knob-shadow-7-y: 5px; --top-shadow-blur: 3px; --inner-bottom-shadow-blur: 1px; --shine-top-opacity: 1; --shine-top-y: 0px; --shine-bottom-opacity: 0; --shine-bottom-y: 5px; } .switch:before, .switch:after { content: ''; display: block; width: var(--size, 120px); height: var(--size, 120px); -webkit-clip-path: url(#shape); clip-path: url(#shape); } .switch:before { --size: 124px; background: -webkit-gradient(linear, left top, left bottom, from(var(--c-stroke-top)), to(var(--c-stroke-bottom))); background: linear-gradient(var(--c-stroke-top), var(--c-stroke-bottom)); position: absolute; left: -2px; top: -2px; -webkit-clip-path: url(#shape-outer); clip-path: url(#shape-outer); } .switch:after { box-shadow: inset 0 3px var(--top-shadow-blur) var(--c-background-top-shadow), inset 0 -5px 5px var(--c-background-bottom-shadow); background: -webkit-gradient(linear, left top, left bottom, from(var(--c-background-top)), to(var(--c-background-bottom))); background: linear-gradient(var(--c-background-top), var(--c-background-bottom)); border-radius: 36px; } .switch .inner { width: 40px; height: 60px; padding: 5px; border-radius: 12.5px; position: absolute; left: 40px; top: 30px; z-index: 1; background: var(--c-inner); box-shadow: 0 -1.5px 1.5px var(--c-inner-top-shadow), 0 1.5px var(--inner-bottom-shadow-blur) var(--c-inner-bottom-shadow), inset 0 5px 14px var(--c-inner-inset-shadow); } .switch .inner:before, .switch .inner:after { content: ''; display: block; } .switch .inner:before { width: 30px; height: 50px; border-radius: 9px; background: -webkit-gradient(linear, left top, left bottom, from(var(--c-knob-stroke-top)), to(var(--c-knob-stroke-bottom))); background: linear-gradient(var(--c-knob-stroke-top), var(--c-knob-stroke-bottom)); box-shadow: 0 var(--knob-shadow-1-y) var(--knob-shadow-1-blur) var(--knob-shadow-1-spread) var(--c-knob-shadow-1), 0 var(--knob-shadow-2-y) var(--knob-shadow-2-blur) rgba(7, 7, 37, 0.07), 0 var(--knob-shadow-3-y) var(--knob-shadow-3-blur) rgba(7, 7, 37, 0.13), 0 var(--knob-shadow-4-y) var(--knob-shadow-4-blur) rgba(7, 7, 37, 0.11), 0 2px 1.5px rgba(7, 7, 37, 0.09), 0 0.85px 0.5px rgba(7, 7, 37, 0.05), 0 var(--knob-shadow-7-y) 15px rgba(0, 0, 0, 0.25); } .switch .inner:after { width: 28px; height: 48px; border-radius: 8.5px; position: absolute; left: 6px; top: 6px; background: -webkit-gradient(linear, left top, left bottom, from(var(--c-knob-inner-top)), color-stop(var(--c-knob-inner-middle-top)), color-stop(var(--c-knob-inner-middle-bottom)), to(var(--c-knob-inner-bottom))); background: linear-gradient(var(--c-knob-inner-top), var(--c-knob-inner-middle-top), var(--c-knob-inner-middle-bottom), var(--c-knob-inner-bottom)); box-shadow: inset 0 var(--knob-inner-shadow-top-y) 1.5px var(--c-knob-inner-shadow-top), inset 0 var(--knob-inner-shadow-bottom-y) 1.25px var(--c-knob-inner-shadow-bottom); } .switch .inner .shine { position: absolute; left: 6px; right: 6px; top: 0; bottom: 0; z-index: 1; border-left: 1px solid; border-right: 1px solid; -webkit-border-image: -webkit-gradient(linear, left top, left bottom, color-stop(30%, rgba(0, 0, 0, 0)), color-stop(rgba(0, 0, 0, 0.1)), color-stop(70%, rgba(0, 0, 0, 0))) 1 100%; -webkit-border-image: linear-gradient(rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0) 70%) 1 100%; -o-border-image: linear-gradient(rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0) 70%) 1 100%; border-image: -webkit-gradient(linear, left top, left bottom, color-stop(30%, rgba(0, 0, 0, 0)), color-stop(rgba(0, 0, 0, 0.1)), color-stop(70%, rgba(0, 0, 0, 0))) 1 100%; border-image: linear-gradient(rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0) 70%) 1 100%; } .switch .inner .shine:before, .switch .inner .shine:after { content: ''; position: absolute; left: -1px; right: -1px; height: 9px; -webkit-mask-image: linear-gradient(to left, transparent 0%, black 14px, black 50%, black calc(100% - 14px), transparent 100%); mask-image: linear-gradient(to left, transparent 0%, black 14px, black 50%, black calc(100% - 14px), transparent 100%); } .switch .inner .shine:before { border-radius: 11px 11px 0 0; border-top: 1px solid #fff; top: 11px; opacity: var(--shine-top-opacity); -webkit-transform: translateY(var(--shine-top-y)); transform: translateY(var(--shine-top-y)); } .switch .inner .shine:after { border-radius: 0 0 11px 11px; border-bottom: 1px solid #fff; bottom: 11px; opacity: var(--shine-bottom-opacity); -webkit-transform: translateY(var(--shine-bottom-y)); transform: translateY(var(--shine-bottom-y)); } .hint { width: 228px; font-size: 16px; line-height: 1.65; font-weight: 500; position: absolute; left: 50%; top: 50%; color: #93939F; white-space: nowrap; text-align: center; -webkit-transform: translate(-50%, 100px); transform: translate(-50%, 100px); -webkit-animation: show .35s linear forwards; animation: show .35s linear forwards; } .hint a { display: inline-block; position: relative; text-decoration: none; color: #1ca2f1; } .hint a svg { width: 71px; height: 38px; position: absolute; left: 50%; bottom: 0; -webkit-transform: translate(-50%, 5px) translateZ(0); transform: translate(-50%, 5px) translateZ(0); fill: none; stroke: #1ca2f1; stroke-linecap: round; stroke-width: 2px; stroke-dasharray: var(--offset, 69px) 278px; stroke-dashoffset: 361px; -webkit-transition: stroke 0.25s ease var(--stroke-delay, 0s), stroke-dasharray 0.35s; transition: stroke 0.25s ease var(--stroke-delay, 0s), stroke-dasharray 0.35s; } .hint a:hover { --stroke-delay: .1s; --offset: 180px; } @-webkit-keyframes show { from { opacity: 0; } } @keyframes show { from { opacity: 0; } } html { box-sizing: border-box; -webkit-font-smoothing: antialiased; } * { box-sizing: inherit; } *:before, *:after { box-sizing: inherit; } body { display: -webkit-box; display: flex; -webkit-box-pack: center; justify-content: center; -webkit-box-align: center; align-items: center; min-height: 100vh; background: #27272B; font-family: 'Inter', Arial, sans-serif; -webkit-transition: background 0.15s cubic-bezier(0.532, 0, 0.924, 0.862); transition: background 0.15s cubic-bezier(0.532, 0, 0.924, 0.862); } body.active { background: #F6F6F6; }
JavaScript
document.querySelectorAll('.switch').forEach(elem => { elem.addEventListener('click', e => { let active = elem.classList.contains('active') gsap.to(elem, { '--c-background-top': active ? '#75757D' : '#F0F0F0', '--c-background-bottom': active ? '#45454C' : '#E9E9E9', '--c-background-top-shadow': active ? 'rgba(255, 255, 255, .45)' : '#fff', '--c-background-bottom-shadow': active ? 'rgba(0, 0, 0, .3)' : 'rgba(0, 0, 0, .18)', '--c-stroke-top': active ? '#262626' : '#E7E7E7', '--c-stroke-bottom': active ? '#3D3D43' : '#D0D0D0', '--c-inner': active ? '#6D6D6D' : '#EAEAEA', '--c-inner-top-shadow': active ? 'rgba(0, 0, 0, .3)' : 'rgba(156, 56, 0, .42)', '--c-inner-bottom-shadow': active ? 'rgba(255, 255, 255, .18)' : '#FFF3E5', '--c-inner-inset-shadow': active ? 'rgba(0, 0, 0, .14)' : 'rgba(0, 0, 0, .2)', '--c-knob-stroke-top': active ? '#515151' : '#cc4528', '--c-knob-stroke-bottom': active ? '#acacac' : '#f05f21', '--c-knob-inner-top': active ? '#8A8A8A' : '#E94714', '--c-knob-inner-middle-top': active ? '#A1A1A1' : '#E85617', '--c-knob-inner-middle-bottom': active ? '#B4B4B4' : '#FF7324', '--c-knob-inner-bottom': active ? '#BABABA' : '#FF844F', '--c-knob-inner-shadow-top': active ? 'rgba(255, 255, 255, .25)' : 'rgba(255, 170, 109, .44)', '--c-knob-inner-shadow-bottom': active ? 'rgba(0, 0, 0, .3)' : 'rgba(244, 44, 0, .9)', '--c-knob-shadow-1': active ? 'rgba( 7, 7, 37, .16)' : 'rgba(255, 180, 175, .7)', '--shine-top-y': active ? '-5px' : '0px', '--shine-bottom-y': active ? '0px' : '5px', '--knob-inner-shadow-top-y': active ? '2.5px' : '5.5px', '--knob-inner-shadow-bottom-y': active ? '-5.5px' : '-1.5px', '--knob-shadow-1-y': active ? '20px' : '0px', '--knob-shadow-1-blur': active ? '20px' : '2px', '--knob-shadow-1-spread': active ? '0px' : '5px', '--knob-shadow-2-y': active ? '12.5px' : '6.5px', '--knob-shadow-2-blur': active ? '8.5px' : '4.5px', '--knob-shadow-3-y': active ? '6.5px' : '3.5px', '--knob-shadow-3-blur': active ? '4.5px' : '2.5px', '--knob-shadow-4-y': active ? '4px' : '2px', '--knob-shadow-4-blur': active ? '2.5px' : '1.5px', '--knob-shadow-7-y': active ? '15px' : '5px', '--top-shadow-blur': active ? '5px' : '3px', '--inner-bottom-shadow-blur': active ? '1.25px' : '1px', '--shine-top-opacity': active ? 0 : 1, '--shine-bottom-opacity': active ? 1 : 0, duration: .15, ease: 'power1.in', onStart() { (new Audio('https://www.jq22.com/newjs/switch.mp3')).play() elem.dataset.c = (parseInt(elem.dataset.c) || 0) + 1 if(parseInt(elem.dataset.c) == 7) { let hint = document.createElement('div') hint.innerHTML = 'You can’t get enough?
Follow our journey on
Twitter
' hint.classList.add('hint') document.querySelector('body').appendChild(hint) } }, onComplete() { elem.classList.toggle('active') } }) document.querySelector('body').classList.toggle('active') }) })
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>开关切换-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号