纯css实现checkbox多种动画效果
代码语言:html
所属分类:表单美化
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link href="https://fonts.googleapis.com/css?family=Margarine|Rubik:400,500" rel="stylesheet"> <style> body { background: #2e394d; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; } * { box-sizing: border-box; } *:before, *:after { content: ''; position: absolute; } input { height: 40px; left: 0; opacity: 0; position: absolute; top: 0; width: 40px; } .toggle-wrapper { flex: 1 1 calc(100% / 3); min-height: 50vh; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; } @media (max-width: 960px) { .toggle-wrapper { flex: 1 1 calc(100% / 2); } } @media (max-width: 700px) { .toggle-wrapper { flex: 1 1 100%; } } .toggle-wrapper:nth-child(1) { background: #dec387; } .toggle-wrapper:nth-child(2) { background: #de8797; } .toggle-wrapper:nth-child(3) { background: #87aade; } .toggle-wrapper:nth-child(4) { background: #c5de87; } .toggle-wrapper:nth-child(5) { background: #87ded2; } .toggle-wrapper:nth-child(6) { background: #c487de; } .toggle-wrapper:nth-child(7) { background: #de8787; } .toggle-wrapper:nth-child(7) .toggle { transform: translate(-40px, 40px); } .toggle-wrapper:nth-child(8) { background: #decf87; } .toggle-wrapper:nth-child(8) .toggle { transform: translate(-40px, 40px); } .name { width: 80%; position: absolute; font: 500 14px 'Rubik', sans-serif; letter-spacing: .5px; text-transform: uppercase; text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4); bottom: 15px; right: 15px; text-align: right; } .toggle { position: relative; display: inline-block; } label.toggle-item { width: 7em; background: #2e394d; height: 3em; display: inline-block; border-radius: 50px; margin: 40px; position: relative; transition: all .3s ease; transform-origin: 20% center; cursor: pointer; } label.toggle-item:before { display: block; transition: all .2s ease; width: 2.3em; height: 2.3em; top: .25em; left: .25em; border-radius: 2em; border: 2px solid #88cf8f; transition: .3s ease; } .normal label { background: #af4c4c; border: 0.5px solid rgba(117, 117, 117, 0.31); box-shadow: inset 0px 0px 4px 0px rgba(0, 0, 0, 0.2), 0 -3px 4px rgba(0, 0, 0, 0.15); } .normal label:before { border: none; width: 2.5em; height: 2.5em; box-shadow: inset 0.5px -1px 1px rgba(0, 0, 0, 0.35); background: #fff; transform: rotate(-25deg); } .normal label:after { background: transparent; height: calc(100% + 8px); border-radius: 30px; top: -5px; width: calc(100% + 8px); left: -4px; z-index: 0; box-shadow: inset 0px 2px 4px -2px rgba(0, 0, 0, 0.2), 0px 1px 2px 0px rgba(151, 151, 151, 0.2); } #normal:checked + label { background: #4caf50; } #normal:checked + label:before { left: 67px; } .transparent label { background: transparent; border: 3px solid #fff; height: 3.35em; } .transparent label:before { border: 3px solid #fff; width: 2em; height: 2em; top: .3em; left: .3em; background: #fff; } #transparent:checked + label:before { transform: translateX(59px); } .checkcross label:before { content: none; } .checkcross .check { border-radius: 50%; width: 2.5em; height: 2.5em; position: absolute; background: #8BC34A; transition: .4s ease; top: 4.5px; left: 4.5px; } .checkcross .check:before, .checkcross .check:after { height: 4px; border-radius: 10px; background: #fff; transition: .4s ease; } .checkcross .check:before { width: 25px; transform: rotate(-45deg) translate(-6px, 20px); } .checkcross .check:after { width: 10px; transform: rotate(45deg) translate(20px, 11px); } #checkcross:checked + label .check { left: 68px; transform: rotate(360deg); background: #c34a4a; } #checkcross:checked + label .check:before { width: 27px; transform: rotate(-45deg) translate(-8px, 18px); } #checkcross:checked + label .check:after { width: 27px; transform: rotate(45deg) translate(18px, 8px); } #gravity:checked + label { transform: rotate(90deg); } #gravity:checked + label:before { transform: translateX(67px); transition-delay: .2s; transition: 0.6s cubic-bezier(0.895, 0.03, 0.685, 0.22) 0.2s; } .beer-pong label:before { background: #f9f9f9; box-shadow: inset 0 -3px 0 0 #c6c5c5; border: none; width: 2.5em; height: 2.5em; top: .25em; left: .25em; } .beer-pong .cup { top: -3%; right: -118px; border-top: 90px solid #f44336; border-left: 15px solid transparent; border-right: 15px solid transparent; height: 3px; position: absolute; width: 80px; transform-origin: bottom right; transition: 0.2s cubic-bezier(0.42, 0.5, 0.58, 1); } .beer-pong .cup:before { box-shadow: 0 -10px 0 0px rgba(39, 39, 39, 0.1), 0px -20px 0 0px rgba(39, 39, 39, 0.1); border-radius: 3px; overflow: hidden; background: rgba(39, 39, 39, 0.1); width: 120%; left: -5px; height: 4px; top: -40px; } .beer-pong .cup .lid { position: absolute; width: 95px; height: 8px; border-radius: 20px; background: #efefef; bottom: 86px; left: -23px; } .beer-pong .cup .lid:after { background: #efefef; width: 48px; height: 5px; left: 50%; margin-left: -24px; top: 94px; border-radius: 0 0 3px 3px; } #beer-pong:checked ~ .cup { animation: .2s linear cup 1s forwards; } #beer-pong:checked + label:before { animation: 2s linear bounce-off forwards; } @keyframes cup { 0% { transform: none; } 50% { transform: rotate(75deg) translate(10px, 15px); } 90% { transform: rotate(70deg) translate(10px, 15px); } 100% { transform: rotate(75deg) translate(10px, 15px); } } @keyframes bounce-off { 0% { transform: translateY(0); } 10%,25% { transform: translate(-20px, -80px); } 50% { transform: rotate(163deg); transform-origin: 100px -12px; } 70% { transform: rotate(0) translate(-3px, -8px); transform-origin: 100px -12px; } 75% { transform: translate(20px, -8px); } 80% { transform: translate(30px, 0px); } 85% { transform: translate(40px, -3px); } 87% { transform: translate(46px, 0px); } 90% { transform: translate(52px, -1px); } 95% { transform: translate(60px, 0px); } 100% { transform: translate(64px, 0px); } } .dog-rollover label:before { content: none; } .dog-rollover label .dog { display: inline-block; position: absolute; width: 2.5em; height: 2.5em; top: .25em; left: .2em; transition: .6s ease; } .dog-rollover label .eyes { position: absolute; width: 8px; height: 8px; background: #222; border-radius: 50%; transform: translate(8px, 14px); box-shadow: 16px 0 0 #222, 22px -4px 0 12px #e4ac04; } .dog-rollover label .ear { width: 18px; height: 20px; position: absolute; left: -4px; bottom: 80%; background: #f9bb00; margin-bottom: -5px; border-radius: 50% 50% 0 0 / 100% 100% 0 0; box-shadow: inset 4px 0 0 0px #ffffff, inset -4px 0 0 0px #ffffff; transform: rotate(-40deg); } .dog-rollover label .ear.right { transform: rotate(60deg) scaleX(-1); left: auto; transform-origin: center bottom; transition: .4s ease-in-out; right: 0px; } .dog-rollover label .face { overflow: hidden; border-radius: 50%; width: 2.5em; height: 2.5em; position: absolute; background: #fff; z-index: 8; } .dog-rollover label .mouth { position: absolute; background: #222; width: 14px; height: 7px; left: 50%; margin-left: -7px; bottom: 12px; border-radius: 2px 2px 20px 20px; bottom: 8px; transform: scale(0); transition: .1s ease; } .dog-rollover label .mouth:before { width: 8px; height: 8px; background: #ec788d; border-radius: 0 0 50% 50%; transform: translate(3px, 5px); } .dog-rollover label:before { border-color: white; background: white; } #doggo:checked ~ .cup { animation: .2s linear cup 1s forwards; } #doggo:checked + label .dog { left: 68px; transform: rotate(360deg); } #doggo:checked + label .mouth { transform: scale(1); transition-delay: .7s; } #doggo:checked + label .ear.right { transform: scaleX(-1) rotate(-35deg); transition-delay: .6s; } .basketball-hoop label { background: #fd.........完整代码请登录后点击上方下载按钮下载查看
网友评论0