div+css实现checkbox拨杆拟物开关效果代码
代码语言:html
所属分类:布局界面
代码描述:div+css实现checkbox拨杆拟物开关效果代码
代码标签: div css checkbox 拨杆 拟物 开关
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" /> <style> body{ background: #e8e8e8; padding: 200px; } * { padding: 0; margin: 0; box-sizing: border-box; } button { font-family: inherit; } .toggle-container { --knob-size: 1.75em; display: flex; justify-content: center; position: relative; } .toggle-input { position: absolute; z-index: 2; bottom: 132.5%; border-radius: 50%; transform: rotate(-25deg); transform-origin: 50% 4.75em; width: var(--knob-size); height: var(--knob-size); opacity: 0; /* fix em sizing */ font: inherit; transition: transform .24s cubic-bezier(.65, 1.35, .5, 1); cursor: pointer; } .toggle-input:checked { transform: rotate(25deg); } .toggle-handle-wrapper { position: absolute; z-index: 1; bottom: -135%; -webkit-mask-image: linear-gradient(to bottom, #000 62.125%, transparent 50%); mask-image: linear-gradient(to bottom, #000 62.125%, transparent 50%); width: 200%; overflow: hidden; } .toggle-handle { display: flex; flex-direction: column; align-items: center; transform: rotate(-25deg); transform-origin: bottom center; transition: transform .24s cubic-bezier(.65, 1.35, .5, 1); } .toggle-input:checked + .toggle-handle-wrapper > .toggle-handle { transform: rotate(25deg); } .toggle-handle-knob { position: relative; z-index: 1; border-radius: 50%; width: var(--knob-size); height: var(--knob-size); background-image: radial-gradient(farthest-corner at 70% 30%, #fedee2 4%, #d63534 12% 24%, #a81a1a 50% 65%, #d63534 75%); transition: transform .24s cubic-bezier(.65, 1.35, .5, 1); } .toggle-input:checked + .toggle-handle-wrapper .toggle-handle-knob { transform: rotate(-90deg); } /* toggle handle knob hover inner shadow */ .toggle-handle-knob::after { content: ''; position: absolute; top: 0; left: 0; border-radius: inherit; width: 100%; height: 100%; box-shadow: inset 0 0 8px 2px rgb(255 255 255 / .4); opacity: 0; transition: opacity .2s; } @media (hover: hover) { .toggle-input:hover + .toggle-handle-wrapper .toggle-handle-knob::after, .toggle-in.........完整代码请登录后点击上方下载按钮下载查看
网友评论0