纯css实现3d滚球开关效果
代码语言:html
所属分类:表单美化
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> Toy Toggle Switch</title> <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"> <style> *, *:before, *:after { border: 0; box-sizing: border-box; margin: 0; padding: 0; } body { background: linear-gradient(#fff,#ccc); display: flex; height: 100vh; --on: #88e661; --off: #f0f0f0; --transDur: 0.6s; } input { position: fixed; transform: translateX(-100%); } .toy-toggle { background: radial-gradient(attop left,#fff 10%,#fff0 20%), radial-gradient(at top right,#fff 20%,#e4e4e4 35%); border-radius: 6em; box-shadow: 0 0 0.25em #0002, 0 3em 1.5em 0.5em #0002; cursor: pointer; display: block; font-size: 12px; position: relative; margin: auto; width: 20em; height: 12em; -webkit-tap-highlight-color: transparent; } .toy-toggle div { position: absolute; } .toy-toggle > div { top: 50%; left: 50%; } .toy-toggle > div:not(.handle) { transform: translate(-50%,-50%); } .border1 { background: #f0f0f0; border-radius: 5.5em; box-shadow: 0 0 0.2em 0.1em #f0f0f0; width: 19em; height: 11em; } .border2 { background: linear-gradient(0deg,#fff 33%,#ccc 45%); border-radius: 4.75em; box-shadow: 0 0 0.2em 0.3em #f0f0f0 inset; width: 16.5em; height: 9.5em; } .border3, .handle { background: linear-gradient(90deg, var(--on) 50%, var(--off) 0); } .border3 { background-position: 75% 0; background-size: 200% 100%; border-radius: 4.25em; box-shadow: 0 0 0.1em 0.1em #ddd inset, 0 1.5em 1.5em 1em #0004 inset, 0 0 0 4.25em #0002 inset; width: 15.5em; height: 8.5em; transition: background-position var(--transDur) ease-in-out; } .handle { border-radius: 50%; box-shadow: 0 0 0.5em 0 #0007; width: 8.5em; height: 8.5em; transform: tran.........完整代码请登录后点击上方下载按钮下载查看
网友评论0