3D css实现公园街道透视效果
代码语言:html
所属分类:三维
代码描述:3D css实现公园街道透视效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> @charset "UTF-8"; @font-face { font-family: 'VenturisSansADFLt-Bold'; src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/25387/VenturisSansADFLt-Bold.ttf.woff") format("woff"), url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/25387/VenturisSansADFLt-Bold.ttf.svg#VenturisSansADFLt-Bold") format("svg"), url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/25387/VenturisSansADFLt-Bold.ttf.eot"), url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/25387/VenturisSansADFLt-Bold.ttf.eot?#iefix") format("embedded-opentype"); font-weight: normal; font-style: normal; } :root { --zoom: 1; --zoom-square: calc( var(--zoom) * var(--zoom) ); --camera-x: 0; --camera-y: 0; --row-count: 0; --col-count: 0; --tile-width: 1em; --gap-width: calc(var(--tile-width) * 5 / 100); --total-tile-width: calc(1em + var(--gap-width)); --gap-color: #666; } body { height: 100vh; display: grid; -webkit-box-pack: center; justify-content: center; -webkit-box-align: center; align-items: center; overflow: hidden; font-size: 7vmin; -webkit-perspective: 150vmin; perspective: 150vmin; background: #cfe2e3; } .loading-overlay { position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); width: 100%; height: 100%; display: -webkit-box; display: flex; -webkit-box-pack: center; justify-content: center; -webkit-box-align: center; align-items: center; background: rgba(255, 255, 255, 0.85); } .has-loaded .loading-overlay { display: none; } .loading-message { font-size: 3rem; } .loading-message::after { content: "✨"; -webkit-animation: loading-message .5s infinite; animation: loading-message .5s infinite; } @-webkit-keyframes loading-message { from, to { content: "Loading ✨"; } 33% { content: "Loading 🍓"; } 66% { content: "Loading ⚡️"; } } @keyframes loading-message { from, to { content: "Loading ✨"; } 33% { content: "Loading 🍓"; } 66% { content: "Loading ⚡️"; } } .tile { width: calc(1 * var(--tile-width)); height: calc(1 * var(--tile-width)); display: grid; gap: var(--gap-width); background: var(--gap-color); } .enable-shadows .tile span { box-shadow: inset calc(0.02 * var(--tile-width)) calc(0.02 * var(--tile-width)) calc(0.06 * var(--tile-width)) rgba(255, 200, 50, 0.25), inset calc(-0.02 * var(--tile-width)) calc(-0.02 * var(--tile-width)) calc(0.08 * var(--tile-width)) rgba(30, 10, 0, 0.5); } .tile.half-vertical { width: calc(0.3 * var(--tile-width)); height: calc(0.4 * var(--tile-width)); } .tile.masonry-vertical { grid-template: .6fr 1.4fr / 1fr; width: calc(0.3 * var(--tile-width)); } .tile.masonry-vertical.odd { grid-template: 1.4fr .6fr / 1fr; } .tile.half-horizontal { width: calc(0.475 * var(--tile-width)); height: calc(0.33 * var(--tile-width)); } .tile.single-horizontal { height: calc(0.33 * var(--tile-width)); } .tile.vertical { grid-template: 1fr/repeat(3, 1fr); } .tile.horizontal { grid-template: repeat(3, 1fr)/1fr 1fr; } .tile.horizontal :first-child { grid-area: 1 / span 2; } .tile.horizontal :last-child { grid-area: 3 / span 2; } .wall { position: relative; background: var(--gap-color); -webkit-transform-style: preserve-3d; transform-style: preserve-3d; -webkit-transform: rotateX(calc(var(--camera-y) * -15deg)) rotateY(calc(var(--camera-x) * 15deg)) scale(calc(var(--zoom))); transform: rotateX(calc(var(--camera-y) * -15deg)) rotateY(calc(var(--camera-x) * 15deg)) scale(calc(var(--zoom))); } .wall-rain-shield { position: absolute; top: calc(-0.26 * var(--tile-width)); left: 0; z-index: 5; width: 100%; height: calc(0.4 * var(--tile-width)); background: #bbb; } .enable-3d-transformations .wall-rain-shield { -webkit-transform-origin: top center; transform-origin: top center; -webkit-transform: translateZ(calc(0.6 * var(--tile-width))) rotateX(30deg); transform: translateZ(calc(0.6 * var(--tile-width))) rotateX(30deg); } #wall-half-vertical-tiles { position: relative; z-index: 4; display: grid; gap: var(--gap-width); grid-template: 1fr/repeat(calc(3 * var(--col-count)), 1fr); background: var(--gap-color); } .enable-shadows #wall-half-vertical-tiles { box-shadow: 0 calc(0.25 * var(--tile-width)) calc(0.1 * var(--tile-width)) rgba(0, 0, 0, 0.5); } .enable-shadows #wall-half-vertical-tiles::before { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 100%; box-shadow: inset 0 calc(0.2 * var(--tile-width)) calc(0.1 * var(--tile-width)) rgba(0, 0, 0, 0.5); } .enable-3d-transformations #wall-half-vertical-tiles { -webkit-transform: translateZ(calc(0.6 * var(--tile-width))); transform: translateZ(calc(0.6 * var(--tile-width))); } #wall-masonry-vertical-tiles { position: relative; z-index: 3; display: grid; gap: var(--gap-width); grid-template: 1fr/repeat(calc(3 * var(--col-count)), 1fr); } .enable-shadows #wall-masonry-vertical-tiles { box-shadow: 0 calc(0.25 * var(--tile-width)) calc(0.1 * var(--tile-width)) rgba(0, 0, 0, 0.5); } .enable-3d-transformations #wall-masonry-vertical-tiles { -webkit-transform: translateZ(calc(0.45 * var(--tile-width))); transform: translateZ(calc(0.45 * var(--tile-width))); } #wall-half-horizontal-tiles { position: relative; z-index: 2; display: grid; gap: var(--gap-width); grid-template: 1fr/repeat(calc(2 * var(--col-count)), 1fr); } .enable-shadows #wall-half-horizontal-tiles { box-shadow: 0 calc(0.25 * var(--tile-width)) calc(0.1 * var(--tile-width)) rgba(0, 0, 0, 0.5); } .enable-3d-transformations #wall-half-horizontal-tiles { -webkit-transform: translateZ(calc(0.3 * var(--tile-width))); transform: translateZ(calc(0.3 * var(--tile-width))); } #wall-single-horizontal-tiles { position: relative; z-index: 1; display: grid; gap: var(--gap-width); grid-template: 1fr/repeat(var(--col-count), 1fr); } .enable-shadows #wall-single-horizontal-tiles { box-shadow: 0 calc(0.25 * var(--tile-width)) calc(0.1 * var(--tile-width)) rgba(0, 0, 0, 0.5); } .enable-3d-transformations #wall-single-horizontal-tiles { -webkit-transform: translateZ(calc(0.15 * var(--tile-width))); transform: translateZ(calc(0.15 * var(--tile-width))); } #wall-front-tiles { position: relative; display: grid; gap: var(--gap-width); grid-template: repeat(var(--row-count), 1fr)/repeat(var(--col-count), 1fr); } .left-shadow { display: none; position: absolute; top: 0; left: 0; z-index: 1; width: 100%; height: 100%; box-shadow: inset calc(1.65 * var(--tile-width)) 0 calc(0.08 * var(--tile-width)) rgba(0, 0, 0, 0.5); -webkit-transform: translateZ(1px); transform: translateZ(1px); } .enable-shadows .left-shadow { display: block; } .window { position: absolute; top: 0; left: 50%; -webkit-transform: translateX(-50%); transform: translateX(-50%); width: calc(5 * var(--total-tile-width)); height: calc(6 * var(--total-tile-width)); overflow: hidden; background: rgba(22, 36, 42, 0.5); -webkit-perspective: 150vmin; perspective: 150vmin; } .window .left-shadow { left: calc(-1.5 * var(--tile-width)); } .room { position: relative; overflow: hidden; width: 100%; height: 100%; } .room-photo { position: absolute; top: calc(-2 * var(--tile-width)); left: calc(-3 * var(--tile-width)); max-width: 300%; opacity: 1; -webkit-transform: translate(calc(var(--camera-x) * -1% * var(--zoom-square)), calc(var(--camera-y) * -1% * var(--zoom-square))) scale(calc( 3 - var(--zoom) )); transform: translate(calc(var(--camera-x) * -1% * var(--zoom-square)), calc(var(--camera-y) * -1% * var(--zoom-square))) scale(calc( 3 - var(--zoom) )); } .enable-win-reflection .room-photo { opacity: calc(var(--zoom) / 2); } .window-reflection-container { position: relative; display: block; width: 100%; height: 100%; } .window-reflection { display: none; position: absolute; top: calc(-8.5 * var(--tile-width)); right: calc(0 * var(--tile-width)); max-width: calc(600% - (150% * var(--zoom))); mix-blend-mode: overlay; -webkit-transform: translate(calc(var(--camera-x) * -3% * var(--zoom-square) / 1.5), calc(var(--camera-y) * -3% * var(--zoom-square) / 1.5)); transform: translate(calc(var(--camera-x) * -3% * var(--zoom-square) / 1.5), calc(var(--camera-y) * -3% * var(--zoom-square) / 1.5)); } .enable-win-reflection .window-reflection { display: block; } .window-frame { position: absolute; top: 0; left: 0; width: 100%; height: 100%; box-shadow: inset 0 0 0 calc(0.25 * var(--tile-width)) #eae4da, inset calc(0.01 * var(--tile-width)) calc(0.01 * var(--tile-width)) 0 calc(0.255 * var(--tile-width)) rgba(0, 0, 0, 0.5), inset 0 0 0 calc(0.5 * var(--tile-width)) #eae4da, inset 0 0 0 calc(0.6 * var(--tile-width)) #816531; } .ventilation-grid { position: absolute; top: 0; right: calc(1.2 * var(--tile-width)); width: calc(0.8 * var(--tile-width)); height: calc(0.8 * var(--tile-width)); background: #777; } .ventilation-grid::after { content: ""; position: absolute; top: 50%; left: 50%; width: 80%; height: 80%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent calc(0.1 * var(--tile-width)), transparent calc(0.14 * var(--tile-width))); } .street-signs { position: absolute; left: calc(0.5 * var(--tile-width)); bottom: calc(1 * var(--tile-width)); height: calc(0.5 * var(--tile-width)); } .street-sign { position: relative; padding: calc(0.25 * var(--tile-width)) calc(0.3 * var(--tile-width)); background: -webkit-gradient(linear, left top, left bottom, from(#eae4da), to(#dad4ca)); background: linear-gradient(to bottom, #eae4da, #dad4ca); font: normal calc(0.4 * var(--tile-width))/calc(0.6 * var(--tile-width)) "VenturisSansADFLt-Bold", sans-serif; text-transform: uppercase; box-shadow: calc(0.02 * var(--tile-width)) calc(0.02 * var(--tile-width)) 2px rgba(0, 0, 0, 0.5); } .street-sign::before, .street-sign::after { content: ""; position: absolute; top: 50%; -webkit-transform: translateY(-50%); transform: translateY(-50%); width: calc(0.15 * var(--tile-width)); height: calc(0.15 * var(--tile-width)); background: #333; border-radius: 100%; } .street-sign::before { left: calc(0.01 * var(--tile-width)); } .street-sign::after { right: calc(0.01 * var(--tile-width)); } .street-sign.swe { letter-spacing: calc(0.06 * var(--tile-width)); } .settings { position: absolute; top: 1rem; left: 1rem; font: normal 1rem/1.6 helvetica, sans-serif; } .settings.inverted { color: white; } .settings[open] { background: rgba(0, 0, 0, 0.9); color: white; } .settings[open] .settings-label::before { content: ""; position: fixed; top: 0; left: 0; bottom: 0; right: 0; z-index: 1; } .settings-label { display: block; width: 28px; height: 28px; padding: .3rem .5rem; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; list-style: none; } .settings-label::-webkit-details-marker { display: none; } .settings .settings-icon { width: 100%; height: 100%; -webkit-transform: none; transform: none; -webkit-transition: -webkit-transform .3s; transition: -webkit-transform .3s; transition: transform .3s; transition: transform .3s, -webkit-transform .3s; } .settings[open] .settings-icon { -webkit-animation: spin120 .5s 1 forwards; animation: spin120 .5s 1 forwards; } @-webkit-keyframes spin120 { to { -webkit-transform: rotate(120deg); transform: rotate(120deg); } } @keyframes spin120 { to { -webkit-transform: rotate(120deg); transform: rotate(120deg); } } .settings:not([open]) .settings-icon:hover, .settings:not([open]) .settings-label:focus-within .settings-icon { -webkit-transform: rotate(30deg); transform: rotate(30deg); } .settings:not([open]) .settings-label:active .settings-icon { -webkit-transform: rotate(45deg); transform: rotate(45deg); } .settings-list { position: absolute; top: 100%; left: 0; z-index: 2; width: -webkit-max-content; width: -moz-max-content; width: max-content; height: -webkit-max-content; .........完整代码请登录后点击上方下载按钮下载查看
网友评论0