上传图片庚城立体三维凹凸效果
代码语言:html
所属分类:三维
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Hind:400,700&display=swap'> <style> * { border: 0; box-sizing: border-box; margin: 0; padding: 0; } :root { font-size: calc(14px + (20 - 14)*(100vw - 320px)/(2560 - 320)); --buttonBg: #2762f3; --buttonHoverBg: #0c48db; --formBg: #fff; --inputBorder: #969696; --inputBg: #fff; --inputDisableBg: #f1f1f1; --pColor: #171717; --toggleBg: #e8e8e8; --toggleBgHover: #dbdbdb; } body, button, input { color: var(--pColor); font: 1em/1.5 "Hind", sans-serif; } body { overflow: hidden; } aside, button, input, .upload-btn input[type=file] { width: 100%; } aside, input[name=toggle] { position: fixed; left: 0; } aside { background: var(--formBg); bottom: 0; transform: translateY(calc(100% - 1.5em)); transition: transform 0.2s ease-in; } form { padding: 1.5em 1.5em 0 1.5em; } button, input { -webkit-appearance: none; -moz-appearance: none; appearance: none; } button, input[type=file], .toggle-btn { cursor: pointer; } button:hover, button:focus, input[type=file]:hover + button, input[type=file]:focus + button { background: var(--buttonHoverBg); } button, .range-slider input[type=range] { border-radius: 0.375em; } button { background: var(--buttonBg); color: #fff; display: block; margin-bottom: 1.5em; padding: 0.75em 1em; transition: background 0.1s linear; } input, label, .toggle-btn:before { display: block; } input, input[type=file] + button, .upload-btn { margin-bottom: 0.75em; } input { background: var(--inputBg); border-radius: 0.25em; box-shadow: 0 0 0 1px var(--inputBorder) inset; padding: 0.375em; } input:disabled { background: var(--inputDisableBg); cursor: not-allowed; text-overflow: ellipsis; } input[name=toggle] { top: -1.5em; } input[name=toggle]:checked + aside { transform: translateY(0); } label { font-weight: bold; } canvas { cursor: move; } .toggle-btn, .upload-btn { position: relative; } .toggle-btn:before, .upload-btn input[type=file] { position: absolute; } .toggle-btn { background: var(--toggleBg); text-align: center; } .toggle-btn:before { content: ""; top: 33%; left: calc(50% - 0.5em); width: 0; height: 0; border-left: 0.5em solid transparent; border-right: 0.5em solid transparent; border-bottom: 0.5em solid; } input[name=toggle]:checked + aside .toggle-btn:before { border-top: 0.5em solid; border-bottom: 0; } .toggle-btn:hover, input[name=toggle]:focus + aside .toggle-btn { background: var(--toggleBgHover); } .upload-btn, .sr { overflow: hidden; } .upload-btn input[type=file] { padding-top: 2.5em; opacity: 0; top: 0; left: 0; height: 3em; } .range-slider { display: flex; } .range-slider input[type=range], .range-slider input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; } .range-slider input[type=range] { margin: 0.75em 0.75em 0.75em 0; height: 0.75em; padding: 0; } .range-slider input[type=range]::-webkit-slider-thumb { background: var(--buttonBg); border-radius: 50%; cursor: pointer; transition: background 0.1s linear; width: 1.5em; height: 1.5em; } .range-slider input[type=range]::-webkit-slider-thumb:hover { background: var(--buttonHoverBg); } .range-slider input[type=range]::-moz-range-thumb { background: var(--buttonBg); border: 0; border-radius: 50%; cursor: pointer; transition: background 0.1s linear; width: 1.5em; height: 1.5em; } .range-slider input[type=range]::-moz-range-thumb:hover { background: var(--buttonHoverBg); } .range-slider input[type=range] + input { width: 3.75em; } .sr { display: inline-block; width: 1px; height: 1px; } /* Queries */ @media screen and (min-width: 768px) { aside { width: 20em; } } @media (prefers-color-scheme: dark) { :root { --formBg: #3d3d3d; --inputBg: #242424; --inputDisableBg: #242424; --inputBorder: #242424; --pColor: #f1f1f1; --toggleBg: #171717; --toggleBgHover: #0a0a0a; } } </style> </head> <body translate="no"> <input type="checkbox" id="toggle" name="toggle" value="Toggle Image Panel" checked> <aside> <label class="toggle-btn" for="toggle"> <span class="sr">图片选择</span> </label> <form action=""> <label for="img_upload">图片</label> <div class="upload-btn"> <input id="img_upload" name="img_upload" type="file" accept="image/*"> <button type="button" for="img_upload" tabindex="-1">上传</button> <input id="img_name" name="img_name" type="text" placeholder="No file selected" disabled> </div> <label for="max_height">最大高度</label> <div class="range-slider"> <input name="max_height" type="range" min="2" max="16" value="8"> <input id="max_height" name="max_height" type="number" min="2" max="16" value="8"> </div> <button name="reset_camera" type="button">重置a</button> </form> </aside> <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/three-min.js"></script> <script src='http://repo.bfw.wiki/bfwrepo/js/OrbitControls.js'></script> <script > window.addEventListener("DOMContentLoaded", app); function app() { var form = document.querySelector("form"), imgUpload = document.getElementsByName("img_upload")[0], imgName = document.getElementsByName("img_name")[0], maxHeightRange = document.getElementsByName("max_height")[0], maxHeightNumber = document.getElementsByName("max_height")[1], resetCamBtn = document.getElementsByName("reset_camera")[0], canvas = document.createElement("canvas"), c = canvas.getContext("2d"), scene, renderer, camera, camControls, img = null, worldHeight = +maxHeightRange.value, worldSize = 64, terrainGeo = new THREE.Geometry(), terrainYPoints = [], adjustWindow = () => { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); }, changeMaxHeight = function () { // keep input within range if (+this.value > this.max) this.value = this.max;else if (+this.value < this.min) this.value = this.min; // dynamically update values worldHeight = this.value; maxHeightRange.value = worldHeight; maxHeightNumber.value = worldHeight; refreshTerrain(); }, getLightness = (R, G, B) => { let r = R / 255, g = G / 255, b = B / 255, cmin = Math.min(r, g, b), cmax = Math.max(r, g, b), light = (cmax + cmin) / 2; return light; }, handleImgUpload = e => { return new Promise((resolve, reject) => { let target = !e ? imgUpload : e.target; if (target.files.length) { let reader = new FileReader(); reader.onload = e2 => { img = new Image(); img.src = e2.target.result; img.onload = () => { resolve(); }; img.onerror = () => { img = null; reject("Image nullified due to file corruption or non-image upload"); }; imgName.placeholder = target.files[0].name; }; reader.readAsDataURL(target.files[0]); } }); }, imgUploadValid = () =&g.........完整代码请登录后点击上方下载按钮下载查看
网友评论0