1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>小鸟向前冲</title> <style> *, *::before, *::after { box-sizing: border-box; user-select: none; } body { margin: 0; display: flex; justify-content: center; align-items: center; min-height: 100vh; } .city { overflow: hidden; position: relative; width: 100vw; height: 100vh; } .score { position: absolute; font-size: 3vmin; right: 1vmin; top: 1vmin; z-index: 999; }
.start-control { position: absolute; font-size: 5vmin; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 999;
} .hide { display: none; } .bg_ground { --left: 0; position: absolute; width: 100%; height: 100vh; bottom: 0; left: calc(var(--left) * 1%); }
.bird { --bottom: 10; position: absolute; left: 1%; height: 10%; bottom: calc(var(--bottom) * 1%); } </style>
</head> <body> <div class="city" id="city"> <div class="score">得分:<span>0</span></div> <div class="start-control">按任意键继续</div> <img src="imgs/full-background.png" class="bg_ground" > <img src="imgs/full-background.png" class="bg_ground" > <img src="imgs/frame-1.png" class="bird"> </div> </body>
<script> function setElementProperty(elemObj, prop, value) { elemObj.style.setProperty(prop, value) } function getElementProperty(elemObj, prop) { return parseFloat(getComputedStyle(elemObj).getPropertyValue(prop)) || 0 } function incrementElementProperty(elemObj, prop, incVal) { setElementProperty(elemObj, prop, getElementProperty(elemObj, prop) + incVal) } const bgGroundElements = document.querySelectorAll(".bg_ground") function setupBgGround() { setElementProperty(bgGroundElements[0], "--left", 0) setElementProperty(bgGroundElements[1], "--left", 100) } </script> </html>
|