css+js实现立体回弹小球的checkbox开关效果代码
代码语言:html
所属分类:其他
代码描述:css+js实现立体回弹小球的checkbox开关效果代码
代码标签: css js 立体 回弹 小球 checkbox 开关
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"> <style> * { border: 0; box-sizing: border-box; margin: 0; padding: 0; } :root { --hue: 223; --trans-dur: 0.3s; font-size: calc(48px + (96 - 48) * (100vw - 320px) / (2560 - 320)); } body, input { color: hsl(var(--hue), 90%, 10%); font: 1em/1.5 sans-serif; } body { background-image: linear-gradient(45deg, hsl(var(--hue), 90%, 67%), hsl(var(--hue), 90%, 70%)); display: flex; height: 100vh; } .switch { --dur: 2.5s; margin: auto; position: relative; } .switch__ball, .switch__ball:before, .switch__ball-shadow, .switch__ball-shadow:before, .switch__ball-shadow-outer, .switch__ball-texture, .switch__label, .switch__shadow, .switch__shadow:before, .switch__shadow:after, .switch__shadow-inner { display: block; position: absolute; top: 0; left: 0; } .switch__ball, .switch__ball:before, .switch__ball-shadow, .switch__ball-shadow-outer, .switch__shadow { border-radius: 50%; pointer-events: none; width: 1.375em; height: 1.375em; } .switch__ball, .switch__shadow { overflow: hidden; } .switch__ball, .switch__ball-shadow, .switch__ball-shadow-outer { z-index: 3; } .switch__ball { top: 0.0625em; left: 0.0625em; } .switch__ball:before { background-image: linear-gradient(60deg, hsl(var(--hue), 90%, 10%, 0.2), hsla(var(--hue), 90%, 10%, 0)); box-shadow: 0.125em -0.0625em 0.125em hsla(var(--hue), 90%, 70%, 0.5) inset, 0.25em -0.125em 0.25em hsla(var(--hue), 90%, 10%, 0.5) inset, -0.0625em 0.0625em 0.0625em rgba(255, 255, 255, 0.7) inset; content: ""; z-index: 1; } .switch__ball-shadow { top: 0.0625em; left: 0.0625em; width: 0.6875em; } .switch__ball-shadow:before { background-color: hsla(var(--hue), 90%, 40%, 0.7); border-radius: 100% 0 0 100%/50% 0 0 50%; content: ""; width: 100%; height: 100%; transform: rotate(-15deg) scale(1.15, 1); transform-origin: 100% 50%; } .switch__ball-shadow-outer { box-shadow: 0 0 0.25em hsl(var(--hue), 90%, 30%); top: 0.3125em; left: 0.0625em; width: 0.875em; height: 0.875em; } .switch__ball-texture { background: url("https://assets.codepen.io/416221/speckled.jpg") 0 0/100% 100%; right: 0; left: auto; width: 300%; height: 100%; } .switch, .switch__input { border-radius: 50%; position: relative; -webkit-tap-highlight-color: transparent; } .switch__input, .switch__shadow, .switch__shadow-inner { border-radius: 0.75em; width: 3em; height: 1.5em; } .switch__input { box-shadow: -0.125em 0.25em 0.25em hsl(var(--hue), 90%, 63%) inset, -0.125em -0.125em 0.25em hsl(var(--hue), 90%, 68%) inset, 0 -0.0625em 0.125em hsl(var(--hue), 90%, 60%), 0 0 0.25em hsl(var(--hue), 90%, 78%); cursor: pointer; display: block; -webkit-appearance: none; appearance: none; } .switch__input:before, .switch__input:after { content: ""; display: block; position: absolute; width: 50%; height: 100%; z-index: 2; } .switch__input:before { border-radius: 50% 0 0 50%; box-shadow: 0.0625em 0.0625em 0.0625em hsla(var(--hue), 90%, 40%, 0.5) inset; -webkit-mask: linear-gradient(-45deg, rgba(0, 0, 0, 0) 50%, black); } .switch__input:after { background: linear-gradient(69deg, hsla(var(--hue), 90%, 30%, 0) 60%, hsla(var(--hue), 90%, 30%, 0.75) 65%, hsla(var(--hue), 90%, 30%, 1) 80%); border-radius: 0 50% 50% 50%; box-shadow: -0.0625em 0.0625em 0.0625em hsl(var(--hue), 90%, 70%) inset; clip-path: polygon(16% 0, 100% 0, 100% 100%, 65% 100%); -webkit-mask: linear-gradient(90deg, rgba(0, 0, 0, 0) 20%, black); opacity: 0; right: 0; } .switch__input:checked ~ .switch__ball, .switch__input:checked ~ .switch__ball-shadow, .switch__input:checked ~ .switch__ball-shadow:before, .switch__input:checked ~ .switch__ball-shadow-outer, .switch__input:checked ~ .switch__ball .switch__ball-texture, .switch__input:checked:before, .switch__input:checked:after { animation: ball-roll var(--dur) forwards; } .switch__input:checked ~ .switch__ball-shadow { animation-name: ball-roll-shadow; } .switch__input:checked ~ .switch__ball-shadow:before { animation-name: ball-roll-shadow-tilt; } .switch__input:checked ~ .switch__ball .switch__ball-texture { animation-name: ball-roll-texture; } .switch__input:checked:before { ani.........完整代码请登录后点击上方下载按钮下载查看
网友评论0