css实现蛋糕品种选择点击切换效果代码
代码语言:html
所属分类:表单美化
代码描述:css实现蛋糕品种选择点击切换效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> :root { --zoom:100; --animation-speed:150; --animation-state:running; --float-duration:1.4s; --tilt-duration:1.2s; --slide-duration:.6s; --slide-max-exposure:72%; --mass:10.5rem; --cake-initial-position:46%; --cake-end-position:50%; --cake-tilt:-2deg; --cake-initial-shadow:.8; --cake-end-shadow:1; --cake-shadow-rotate:40deg; --cake-shadow-offset:230rem; --cake-shadow-blur:15rem } @-webkit-keyframes cake-shadow { to { transform:var(--shadow-transform) scale(var(--cake-end-shadow)) } }@keyframes cake-shadow { to { transform:var(--shadow-transform) scale(var(--cake-end-shadow)) } }@-webkit-keyframes cake-float { to { top:var(--cake-end-position) } }@keyframes cake-float { to { top:var(--cake-end-position) } }@-webkit-keyframes cake-tilt { to { transform:rotate(var(--cake-tilt)) } }@keyframes cake-tilt { to { transform:rotate(var(--cake-tilt)) } }:root { --unit:1vmin; --available-screen-min:665; --px:calc(var(--zoom) *(var(--unit) / var(--available-screen-min))); --clip-path-top:polygon(75% 21%,91.7% 59%,100% 100%,0 100%,55.3% 0); --clip-path-side:polygon(0% .3%,100% 1.2%,93.7% 91%,5.6% 98.4%) } html,body { height:100%; margin:0; overflow:hidden; touch-action:none; background-color:#fff } * { font-size:calc(1 * var(--px)) } label { font-size:0!important } .slide,.slide div,.slide div::before,.slide div::after { transform-style:preserve-3d; background-repeat:no-repeat } label { order:2 } input { order:1 } input[type="radio"] { border-width:0!important; clip:rect(1px,1px,1px,1px)!important; height:1px!important; overflow:hidden!important; padding:0!important; position:absolute!important; white-space:nowrap!important; width:1px!important } #controls { position:absolute; font-size:0; z-index:500; left:50%; bottom:max(6rem,90px); transform:translateX(-50%); width:100%; display:flex; place-content:center } #controls label { --diameter:max(64rem,28px); cursor:pointer; position:relative; width:var(--diameter); height:var(--diameter); box-sizing:border-box; display:inline-block; margin:0; transform:scale(1); transition:all cubic-bezier(0.68,-0.55,0.27,1.55) 200ms; -webkit-tap-highlight-color:transparent } #controls label::before { content:""; position:absolute; left:0; top:0; width:100%; height:100%; border-radius:50%; background-color:var(--p-color-1); transform:scale(var(--s,0.8)); transition:inherit; box-shadow:var(--sb,0 0 0 0 transparent),0 0 0 0 transparent } @media(orientation:landscape) { #controls { --landscape-factor:1; left:30rem; bottom:50%; transform:translateY(50%); width:auto; height:100%; flex-direction:column } }@media(orientation:portrait) { #controls label { margin-inline:3rem!important } }label:nth-of-type(1) { --p-color-2:hsl(42,100%,91%); --p-color-1:hsl(3,74%,28%) } label:nth-of-type(2) { --p-color-1:hsl(24,100%,56%); --p-color-2:hsl(29,88%,77%) } label:nth-of-type(3) { --p-color-2:#ffe6a3; --p-color-1:hsl(18,100%,71%) } label:nth-of-type(4) { --p-color-1:hsl(18,62%,27%); --p-color-2:hsl(19,62%,37%) } label:nth-of-type(5) { --p-color-1:hsl(274,45%,40%); --p-color-2:hsl(21,41%,87%) } label:nth-of-type(6) { --p-color-1:hsl(157,24%,29%); --p-color-2:hsl(42,84%,78%) } main,.slide { position:absolute; left:0; top:0; width:100%; height:100% } .slide { transition:all ease-out calc(var(--slide-duration) *(100 / var(--animation-speed))); transition-delay:calc(var(--slide-duration) *(100 / var(--animation-speed))); -webkit-clip-path:circle(0% at center); clip-path:circle(0% at center) } .flavor:nth-of-type(1):checked ~ main>div:nth-of-type(1),.flavor:nth-of-type(2):checked ~ main>div:nth-of-type(2),.flavor:nth-of-type(3):checked ~ main>div:nth-of-type(3),.flavor:nth-of-type(4):checked ~ main>div:nth-of-type(4),.flavor:nth-of-type(5):checked ~ main>div:nth-of-type(5),.flavor:nth-of-type(6):checked ~ main>div:nth-of-type(6) { transition-delay:0ms; -webkit-clip-path:circle(var(--slide-max-exposure) at center); clip-path:circle(var(--slide-max-exposure) at center); z-index:100 } .flavor:checked ~ #controls label { opacity:.6 } .flavor:nth-of-type(1):checked ~ #controls label:nth-of-type(1),.flavor:nth-of-type(2):checked ~ #controls label:nth-of-type(2),.flavor:nth-of-type(3):checked ~ #controls label:nth-of-type(3),.flavor:nth-of-type(4):checked ~ #controls label:nth-of-type(4),.flavor:nth-of-type(5):checked ~ #controls label:nth-of-type(5),.flavor:nth-of-type(6):checked ~ #controls label:nth-of-type(6) { --s:1; --sb:inset 0 0 0 max(2rem,2px) rgba(0,0,0,0.2); opacity:1; margin-block:calc(var(--landscape-factor,0) * 19rem) } .flavor:nth-of-type(1):focus-visible ~ #controls label:nth-of-type(1)::before,.flavor:nth-of-type(2):focus-visible ~ #controls label:nth-of-type(2)::before,.flavor:nth-of-type(3):focus-visible ~ #controls label:nth-of-type(3)::before,.flavor:nth-of-type(4):focus-visible ~ #controls label:nth-of-type(4)::before,.flavor:nth-of-type(5):focus-visible ~ #controls label:nth-of-type(5)::before,.flavor:nth-of-type(6):focus-visible ~ #controls label:nth-of-type(6)::before { box-shadow:var(--sb),0 0 9rem 1rem var(--p-color-1) } .pastry,.shadow { position:absolute; left:50% } .slide-redvelvet { background-color:#ffcdb2; --color-shadow:#e8ab8a } .slide-cheese { background-image:radial-gradient(circle at center,#fff1ea,#e8dad3); --color-shadow:#d4c2ba } .slide-strawberry { background-color:#ffc2a4; --color-shadow:rgba(255,97,82,0.3) } .slide-chocolate { background-color:hsl(34,47%,86%); --color-shadow:hsl(35,46%,76%) } .slide-blueberry { background-color:white; --color-shadow:hsl(0,0%,72%) } .slide-lemon { background:#eee; --color-shadow:hsl(0,0%,70%) } .pastry { background-color:blue; border-radius:50%; top:var(--cake-initial-position); width:var(--mass); height:var(--mass); transform:rotate(0); -webkit-animation:cake-float ease-in-out calc(var(--float-duration) *(100 / var(--animation-speed))) alternate infinite,cake-tilt ease calc(var(--tilt-duration) *(100 / var(--animation-speed))) alternate infinite; animation:cake-float ease-in-out calc(var(--float-duration) *(100 / var(--animation-speed))) alternate infinite,cake-tilt ease calc(var(--tilt-duration) *(100 / var(--animation-speed))) alternate infinite; -webkit-animation-play-state:var(--animation-state); animation-play-state:var(--animation-state) } .shadow { top:calc(50%+var(--cake-shadow-offset)); width:280rem; height:75rem; border-radius:50%; background:var(--color-shadow); --shadow-transform:translate(-50%,-50%) rotateX(var(--cake-shadow-rotate)); transform:var(--shadow-transform) scale(var(--cake-initial-shadow)); filter:blur(var(--cake-shadow-blur)); -webkit-animation:cake-shadow ease-in-out calc(var(--float-duration) *(100 / var(--animation-speed))) alternate infinite; animation:cake-shadow ease-in-out calc(var(--float-duration) *(100 / var(--animation-speed))) alternate infinite; -webkit-animation-play-state:var(--animation-state); animation-play-state:var(--animation-state) } .slide .top { position:absolute; left:-166.2rem; bottom:7.5rem; width:347.6rem; height:140rem; transform:rotate(-18.5deg); transform-origin:left bottom } .slide-redvelvet .top::before,.slide-redvelvet .top::after,.slide-redvelvet .fruit::before,.slide-redvelvet .fruit::after,.slide-redvelvet .fruit .cream::before,.slide-redvelvet .fruit .cream::after,.slide-redvelvet .cherry-base::before,.slide-redvelvet .cherry-base::after,.slide-redvelvet .cherry-base .gloss::before,.slide-redvelvet .cherry-base .gloss::after,.slide-redvelvet .side::after { content:""; position:absolute } .slide-redvelvet .cherry-top,.slide-redvelvet .fruit,.slide-redvelvet .fruit .cream,.slide-redvelvet .cherry-base,.slide-redvelvet .side,.slide-redvelvet .side .border,.slide-redvelvet .side .stripes,.slide-redvelvet .side .cream { position:absolute } .slide-redvelvet .side .border,.slide-redvelvet .side .stripes,.slide-redvelvet .side .cream { left:0 } .slide-redvelvet .top::before { left:0; bottom:0; width:100%; height:126rem; background-image:linear-gradient(hsl(45,100%,85%),hsl(2,79.7%,29%)),linear-gradient(hsl(45,100%,95%),hsl(45,100%,93%)); background-size:100% 6rem,100% 100%; background-position:left bottom; -webkit-clip-path:var(--clip-path-top); clip-path:var(--clip-path-top) } .slide-redvelvet .top::after { right:61rem; top:46rem; width:159rem; height:77rem; background-color:hsl(22,83.3%,92.9%); transform:rotate(1deg); filter:blur(16rem); border-radius:50% } .slide-redvelvet .cherry-top { left:85rem; top:27rem; width:53rem; height:77rem; border-radius:50%; transform:rotate(14deg); box-shadow:-4rem 0 0 0 hsl(2.7,73.7%,29.8%),-6rem 0 0 0 hsla(349,82%,49%,0.1) } .slide-redvelvet .fruit { right:65rem; top:-26rem; width:164rem; height:158rem; transform:rotate(18.5deg) scale(1.1); z-index:5 } .slide-redvelvet .fruit::before { left:25rem; bottom:8rem; width:122rem; height:56rem; border-radius:50%; background-color:hsl(45,100%,90%); z-index:-1; filter:blur(7rem) } .slide-redvelvet .fruit::after { left:49rem; bottom:52rem; width:66rem; height:29rem; border-radius:50%; box-shadow:0 11rem 0 10rem hsl(45,100%,96%) } .slide-redvelvet .fruit .cream { left:27rem; bottom:15rem; width:112rem; height:57rem; background:hsl(45,100%,93%); box-shadow:0 0 0 1px hsla(24,71%,85%,0.1); border-radius:50% } .slide-redvelvet .fruit .cream::before { left:13rem; bottom:20rem; width:82rem; height:50rem; background:hsl(46,100%,96%); border-radius:50% } .slide-redvelvet .fruit .cream::after { left:4rem; bottom:9rem; width:96rem; height:50rem; background:hsl(46,100%,96%); border-radius:50% } .slide-redvelvet .cherry-base { left:54rem; bottom:45rem; width:57rem; height:50rem } .slide-redvelvet .cherry-base::before { left:0; top:0; width:44rem; height:50rem; border-radius:50%; background:hsl(5.9,71.7%,44.3%); transform:rotate(-24deg); box-shadow:0 0 0 1px hsla(349,82%,51%,0.1) } .slide-redvelvet .cherry-base::after { right:0; top:0; width:44rem; height:50rem; border-radius:50%; background:hsl(5.9,71.7%,44.3%); transform:rotate(24deg); box-shadow:0 0 0 1px hsla(349,82%,51%,0.1) } .slide-redvelvet .cherry-base .gloss { position:relative; z-index:2 } .slide-redvelvet .cherry-base .gloss::before { left:20rem; top:16rem; width:33rem; height:16rem; background-color:transparent; border-radius:50%; transform:rotate(-18deg); filter:blur(2rem); box-shadow:1px 7px 0 0 hsl(5.9,71.7%,57.3%) } .slide-redvelvet .cherry-base .gloss::after { left:12rem; top:7rem; width:11rem; height:14rem; background-color:hsl(5.9,71.7%,57.3%); border-radius:50%; transform:rotate(41deg); filter:blur(2rem) } .slide-redvelvet .side { left:-165.9rem; top:2.2rem; width:368.2rem; height:300rem; transform:rotateX(49.8deg) rotateY(-27.1deg) skewX(6.4deg) rotateZ(4deg); transform-origin:left top; -webkit-clip-path:var(--clip-path-side); clip-path:var(--clip-path-side); background-image:linear-gradient(to left,hsl(7,99%,64%),hsl(7,99%,68%)); background-size:100% 100% } .slide-redvelvet .side .border { top:0; width:101%; height:34rem; background-image:linear-gradient(0deg,hsl(3,74%,33%),hsl(3,74%,24%)); background-size:100% 100%; background-position:0 0; transform-origin:bottom right; transform:rotate(0.8deg); box-shadow:0 0 12rem 5rem hsl(3,74%,33%) } .slide-redvelvet .side .stripes { top:98rem; width:100%; height:83rem; background-image:linear-gradient(90deg,hsl(6,72%,46%),hsl(6,72%,38%)); background-size:100% 100%; background-position:0 0; box-shadow:0 0 5rem 3rem hsl(6,72%,41%) } .slide-redvelvet .side .cream { bottom:21rem; width:100%; height:33rem; background-image:linear-gradient(90deg,hsl(6,72%,46%),hsl(6,72%,38%)); background-size:100% 100%; background-position:0 0; box-shadow:0 0 18rem 4rem hsl(6,72%,37%); transform-origin:bottom right; transform:rotate(-3deg) } .slide-redvelvet .side::after { left:2rem; top:44rem; width:2rem; height:3rem; border-radius:50%; color:hsla(5.9,71.7%,41.6%,0.37); box-shadow:337rem 39rem 0 0rem currentColor,111rem 21rem 0 1rem currentColor,2rem 178rem 0 0rem currentColor,305rem 182rem 0 1rem currentColor,0rem 24rem 0 0rem currentColor,315rem 97rem 0 0rem currentColor,71rem 120rem 0 1rem currentColor,49rem 260rem 0 1rem currentColor,40rem 42rem 0 0rem currentColor,266rem 102rem 0 1rem currentColor,166rem 30rem 0 1rem currentColor,367rem 295rem 0 1rem currentColor,256rem 113rem 0 1rem currentColor,93rem 271rem 0 0rem currentColor,128rem 27rem 0 0rem currentColor,46rem 158rem 0 0rem currentColor,75rem 215rem 0 1rem currentColor,171rem 210rem 0 0rem currentColor,306rem 28rem 0 0rem currentColor,352rem 111rem 0 1rem currentColor,147rem 83rem 0 0rem currentColor,163rem 184rem 0 1rem currentColor,175rem 143rem 0 0rem currentColor,190rem 288rem 0 0rem currentColor,73rem 99rem 0 1rem currentColor,208rem 267rem 0 0rem currentColor,162rem 198rem 0 0rem currentColor,204rem 282rem 0 0rem currentColor,213rem 215rem 0 1rem currentColor,166rem 10rem 0 1rem currentColor,322rem 77rem 0 1rem currentColor,242rem 46rem 0 0rem currentColor,328rem 133rem 0 0rem currentColor,275rem 188rem 0 1rem currentColor,137rem 33rem 0 1rem currentColor,324rem 118rem 0 0rem currentColor,342rem 180rem 0 0rem currentColor,303rem 161rem 0 0rem currentColor,270rem 102rem 0 1rem currentColor,15rem 162rem 0 1rem currentColor,116rem 6rem 0 1rem currentColor,311rem 287rem 0 0rem currentColor,183rem 134rem 0 1rem currentColor,168rem 161rem 0 1rem currentColor,8rem 20rem 0 0rem currentColor,358rem 86rem 0 0rem currentColor,324rem 259rem 0 1rem currentColor,23rem 24rem 0 1rem currentColor,272rem 50rem 0 0rem currentColor,83rem 201rem 0 1rem currentColor,298rem 190rem 0 0rem currentColor,232rem 289rem 0 1rem currentColor,32rem 132rem 0 0rem currentColor,38rem 107rem 0 1rem currentColor,178rem 228rem 0 1rem currentColor,206rem 58rem 0 0rem currentColor,247rem 13rem 0 0rem currentColor,80rem 255rem 0 0rem currentColor,221rem 185rem 0 1rem currentColor,245rem 56rem 0 1rem currentColor,15rem 281rem 0 1rem currentColor,170rem 57rem 0 1rem currentColor,94rem 115rem 0 1rem currentColor,202rem 191rem 0 0rem currentColor,222rem 227rem 0 0rem currentColor,128rem 35rem 0 0rem currentColor,335rem 161rem 0 1rem currentColor,58rem 175rem 0 1rem currentColor,8rem 63rem 0 1rem currentColor,365rem 293rem 0 0rem currentColor,300rem 263rem 0 1rem currentColor,239rem 13rem 0 1rem currentColor,155rem 267rem 0 1rem currentColor,351rem 145rem 0 0rem currentColor,34rem 295rem 0 0rem currentColor,70rem 33rem 0 0rem currentColor,360rem 173rem 0 1rem currentColor,147rem 283rem 0 1rem currentColor,26rem 207rem 0 1rem currentColor,42rem 290rem 0 1rem currentColor,113rem 186rem 0 1rem currentColor,167rem 177rem 0 1rem currentColor,318rem 228rem 0 1rem currentColor,36rem 0rem 0 1rem currentColor,95rem 121rem 0 1rem currentColor,97rem 11rem 0 0rem currentColor,48rem 39rem 0 0rem currentColor,281rem 179rem 0 1rem currentColor,179rem 178rem 0 1rem currentColor,130rem 64rem 0 1rem currentColor,365rem 154rem 0 0rem currentColor,89rem 98rem 0 0rem currentColor,7rem 3rem 0 1rem currentColor,94rem 194rem 0 1rem currentColor,80rem 98rem 0 1rem currentColor,265rem 295rem 0 0rem currentColor,51rem 250rem 0 1rem currentColor,218rem 124rem 0 1rem currentColor,299rem 145rem 0 0rem currentColor,47rem 238rem 0 1rem currentColor,45rem 55rem 0 0rem currentColor,275rem 297rem 0 0rem currentColor,309rem 33rem 0 1rem currentColor,305rem 192rem 0 0rem currentColor,248rem 291rem 0 1rem currentColor,193rem 95rem 0 1rem currentColor,60rem 295rem 0 1rem currentColor,175rem 223rem 0 1rem currentColor,361rem 138rem 0 0rem currentColor,95rem 223rem 0 1rem currentColor,331rem 209rem 0 0rem currentColor,96rem 91rem 0 0rem currentColor,268rem 225rem 0 1rem currentColor,114rem 284rem 0 0rem currentColor,115rem 200rem 0 0rem currentColor,350rem 93rem 0 0rem currentColor,26rem 132rem 0 1rem currentColor,182rem 12rem 0 0rem currentColor,290rem 265rem 0 0rem currentColor,297rem 44rem 0 0rem currentColor } .slide-cheese .top::before,.slide-cheese .top::after,.slide-cheese .side::after { content:""; position:absolute } .slide-cheese .side,.slide-cheese .side .border,.slide-cheese .side .stripes,.slide-cheese .side .cream { position:absolute } .slide-cheese .side .border,.slide-cheese .side .stripes,.slide-cheese .side .cream { left:0 } .slide-cheese .top::before { left:0; bottom:0; width:100%; height:126rem; background-image:linear-gradient(90deg,#fcae6d,#ffaf5a),linear-gradient(0deg,#ffa960,#ffad56); background-size:100% 23rem,100% 100%; background-position:left bottom; -webkit-clip-path:var(--clip-path-top); clip-path:var(--clip-path-top) } .slide-cheese .top::after { right:61rem; top:46rem; width:159rem; height:77rem; background-color:hsl(24,100%,56%); transform:rotate(1deg); filter:blur(16rem); border-radius:50% } .slide-cheese .side { left:-165.9rem; top:2.2rem; width:368.2rem; height:300rem; transform:rotateX(49.8deg) rotateY(-27.1deg) skewX(6.4deg) rotateZ(4deg); transform-origin:left top; -webkit-clip-path:var(--clip-path-side); clip-path:var(--clip-path-side); background-image:linear-gradient(to left,#fcd2aa,#fde0c6); background-size:100% 100% } .slide-cheese .side .border { top:0; width:101%; height:34rem; background-image:linear-gradient(0deg,#ffa960,#ffad56); background-size:100% 100%; background-position:0 0; transform-origin:bottom right; transform:rotate(0.8deg); box-shadow:0 0 12rem 5rem hsl(29,100%,68%) } .slide-cheese .side .stripes { top:98rem; width:100%; height:83rem; background-image:linear-gradient(to right,hsl(29,88%,80%),hsl(29,88%,74%)); background-size:100% 100%; background-position:0 0; box-shadow:0 0 17rem 0rem hsl(29,88%,78%) } .slide-cheese .side .cream { bottom:21rem.........完整代码请登录后点击上方下载按钮下载查看
网友评论0