纯css实现一个抓娃娃机的效果
代码语言:html
所属分类:游戏
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Comfortaa:400,700&display=swap&text=WINALTHEGS%20'> <style> * { border: 0; box-sizing: border-box; margin: 0; padding: 0; } :root { font-size: calc(16px + (20 - 16) * (100vw - 320px)/(1280 - 320)); } body, button { color: #f2f2f2; font: bold 1em/1.5 Comfortaa, sans-serif; text-align: center; text-transform: uppercase; } body { background: #041644; } .machine { background: rgba(255, 255, 255, 0.1); border-radius: 0.25em; box-shadow: -0.25em 0 0 rgba(0, 0, 0, 0.25) inset, 0.25em 0 0 rgba(255, 255, 255, 0.2) inset, 0 3.5em 0 inset, -1em 0 0 inset, 0 -18em 0 inset, 1em 0 0 inset, 0 -22em 0 rgba(128, 128, 128, 0.3) inset; color: #0b46da; display: flex; justify-content: center; align-content: flex-start; flex-wrap: wrap; margin: 1.5em auto 1em auto; width: 18em; height: 34.5em; } .machine input { position: fixed; top: -1.5em; left: -1.5em; } .machine input:checked ~ .machine__btn { filter: brightness(75%); -webkit-filter: brightness(75%); } .machine input:checked ~ .machine__btn:nth-child(6) { animation: flash 1s 6s steps(1) infinite; visibility: hidden; } .machine input:checked ~ .machine__btn:nth-child(7) { animation: disappear 1s 5s steps(1) forwards; visibility: visible; } .machine input:checked ~ .machine__btn:nth-child(n + 2):nth-child(-n + 5):active ~ .machine__window .machine__crane-z { transform: translateZ(-11.49em); } .machine input:checked ~ .machine__btn:nth-child(n + 2):nth-child(-n + 5):active ~ .machine__window .machine__crane-x { transform: translateX(0.01em); } .machine input:checked ~ .machine__btn:nth-child(n + 2):nth-child(-n + 5):active ~ .machine__window .machine__crane-claw { animation-name: swingClaw2; animation-duration: 0s; } .machine input:checked ~ .machine__window .machine__crane-z, .machine input:checked ~ .machine__window .machine__crane-x { transition: transform 2s 2.75s linear; } .machine input:checked ~ .machine__window .machine__crane-z { transform: translateZ(-11.49em); } .machine input:checked ~ .machine__window .machine__crane-x { transform: translateX(0.01em); } .machine input:checked ~ .machine__window .machine__crane-arm, .machine input:checked ~ .machine__window .machine__crane-claw, .machine input:checked ~ .machine__window .machine__crane-claw .machine__prize, .machine input:checked ~ .machine__window .machine__crane-finger, .machine input:checked ~ .machine__window .machine__crane-palm { animation-duration: 5s; } .machine input:checked ~ .machine__window .machine__crane-arm, .machine input:checked ~ .machine__window .machine__crane-claw, .machine input:checked ~ .machine__window .machine__crane-finger, .machine input:checked ~ .machine__window .machine__crane-palm { animation-timing-function: linear; } .machine input:checked ~ .machine__window .machine__crane-arm { animation-name: lowerArm; } .machine input:checked ~ .machine__window .machine__crane-claw { animation-name: swingClaw2; } .machine input:checked ~ .machine__window .machine__crane-claw .machine__prize { animation-name: liftPrize; animation-timing-function: ease-in; } .machine input:checked ~ .machine__window .machine__crane-finger:first-child { animation-name: grabA; } .machine input:checked ~ .machine__window .machine__crane-finger:nth-child(2) { animation-name: grabB; } .machine input:checked ~ .machine__window .machine__crane-finger:nth-child(3) { animation-name: grabC; } .machine input:checked ~ .machine__window .machine__crane-palm { animation-name: raisePalm; } .machine input:focus ~ .machine__btn:nth-child(6) { filter: brightness(125%); -webkit-filter: brightness(125%); } .machine, .machine__btn, .machine__window, .machine__crane-z, .machine__crane-claw { position: relative; } .machine__roof, .machine__window { width: 16rem; } .machine__roof, .machine__btn span { user-select: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; } .machine__btn { background: #5583f6; border-radius: 50%; box-shadow: 0 0.375em 0 #255ff4; color: #171717; cursor: pointer; display: block; margin: 0 0.125em; width: 3em; height: 2.25em; z-index: 1; } .machine__btn:active { box-shadow: 0 0 0 #255ff4; transform: translateY(0.375em); } .machine__btn:active ~ .machine__window .machine__crane-z, .machine__btn:active ~ .machine__window .machine__crane-x { transition: transform 2s linear; } .machine__btn:focus { filter: brightness(125%); -webkit-filter: brightness(125%); outline: transparent; } .machine__btn--red { background: #f45757; box-shadow: 0 0.375em 0 #f22626; } .machine__btn--red:active { box-shadow: 0 0 0 #f22626; } .machine__btn:nth-child(7), .machine__btn span { position: absolute; } .machine__btn:nth-child(7) { top: 17.5em; right: 0.875em; visibility: hidden; } .machine__btn span { display: inline-block; top: 50%; left: 50%; transform: translate(-50%, -50%); } .machine__btn:nth-child(2):active ~ .machine__window .machine__crane-claw, .machine__btn:nth-child(4):active ~ .machine__window .machine__crane-claw { animation: swingClaw1 1s linear infinite reverse; } .machine__btn:nth-child(3):active ~ .machine__window .machine__crane-claw, .machine__btn:nth-child(5):active ~ .machine__window .machine__crane-claw { animation: swingClaw1 1s linear infinite; } .machine__btn:nth-child(2):active ~ .machine__window .machine__crane-x { transform: translateX(0.01em); } .machine__btn:nth-child(3):active ~ .machine__window .machine__crane-x { transform: translateX(11.5em); } .machine__btn:nth-child(4):active ~ .machine__window .machine__crane-z { transform: translateZ(-11.49em); } .machine__btn:nth-child(5):active ~ .machine__window .machine__crane-z { transform: translateZ(-0.01em); } .machine__roof { background: #f2b926; color: #3c2c01; cursor: default; font-size: 1.25em; height: 2rem; margin: 0.75rem; padding-top: 0.2rem; order: -2; } .machine__window { box-shadow: 0.25em 0 0 rgba(255, 255, 255, 0.2), -0.25em 0 0 rgba(0, 0, 0, 0.25); height: 13em; order: -1; overflow: hidden; margin-bottom: 1em; perspective: 40em; z-index: -1; } .machine__crane-finger, .machine__crane-palm, .machine__prizes, .machine__prize { position: absolute; } .machine__crane-z, .machine__crane-x { transition: transform 10000s linear; } .machine__crane-z { left: 0.75em; transform: translateZ(-11.5em); z-index: -3; } .machine__crane-x { width: 3em; height: 14em; transform: translateX(0); } .machine__crane-arm { background: linear-gradient(#969696, #969696) 50% 0/0.25em 100%; margin: auto; width: 100%; height: 8em; transform: translateY(-8em); } .machine__crane-claw { background: linear-gradient(#969696, #969696) 50% 1em/1.5em 0.25em, linear-gradient(-80deg, rgba(150, 150, 150, 0) 38%, #969696 41% 64%, rgba(150, 150, 150, 0) 67%) 0.25em 1em/1em 2em, linear-gradient(80deg, rgba(150, 150, 150, 0) 38%, #969696 41% 64%, rgba(150, 150, 150, 0) 67%) 1.75em 1em/1em 2em, linear-gradient(#636363, #636363) 50% 0/1em 0.75em, linear-gradient(#575757, #575757) 50% 0.75em/0.75em 1.5em, linear-gradient(#969696, #969696) 50% 2.25em/0.5em 0.5em; transform-origin: 50% 0; top: 8em; width: 100%; height: 6em; } .machine__crane-arm, .machine__crane-claw { background-repeat: no-repeat; } .machine__crane-finger { color: #969696; top: 3em; width: 1.5em; height: 3em; } .machine__crane-finger:first-child, .machine__crane-finger:nth-child(3) { border-top: 0.25em solid; } .machine__cr.........完整代码请登录后点击上方下载按钮下载查看
网友评论0