這篇文章主要介紹了如何使用HTML+CSS+JS制作3D立方體圖像庫的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇如何使用HTML+CSS+JS制作3D立方體圖像庫文章都會(huì)有所收獲,下面我們一起來看看吧。
創(chuàng)新互聯(lián)專注于雙峰企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站,成都商城網(wǎng)站開發(fā)。雙峰網(wǎng)站建設(shè)公司,為雙峰等地區(qū)提供建站服務(wù)。全流程定制網(wǎng)站,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
<html> <head> <meta charset="utf-8"> <script id="jqbb" src="https://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script> <style type="text/css">:root { /* Base font size */ font-size: 10px; /* Border color variable */ --border-color: #e70; } * { box-sizing: border-box; } body { font-family: "Montserrat", Arial, sans-serif; font-weight: 500; line-height: 1.5; text-align: center; min-height: 100vh; padding: 4rem 2rem; color: #fafafa; background-color: #080808; } h2 { font-size: 4rem; } h3 { font-size: 2rem; margin-bottom: 2.5rem; } .cube-container { position: relative; width: 30rem; height: 30rem; margin: 18rem auto 6rem; perspective: 100rem; } .cube { position: absolute; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 1s cubic-bezier(0.32, 0.05, 0.35, 1.6); } .cube-face-image { display: block; position: absolute; /* opacity: 0.95; */ /* border: 0.2rem solid #fafafa; */ box-shadow: 0 0 0.5rem #fff, 0 0 1.5rem var(--border-color), 0 0 3rem var(--border-color); } .image-buttons { display: grid; grid-template-columns: repeat(3, auto); grid-gap: 1.5rem; justify-content: center; } .image-buttons input { border: 0.2rem solid #fafafa; } .image-buttons input:focus { outline: none; border: 0.2rem solid var(--border-color); } /* Transform images to create cube */ .image-1 { transform: translateZ(15rem); } .image-2 { transform: rotateX(-180deg) translateZ(15rem); } .image-3 { transform: rotateY(90deg) translateZ(15rem); } .image-4 { transform: rotateY(-90deg) translateZ(15rem); } .image-5 { transform: rotateX(90deg) translateZ(15rem); } .image-6 { transform: rotateX(-90deg) translateZ(15rem); } /* Transform cube to show correct image */ .cube.initial-position { transform: translateZ(-15rem) translateY(-2rem) rotateX(-15deg) rotateY(18deg) rotateZ(2deg); } .cube.show-image-1 { transform: translateZ(-15rem); } .cube.show-image-2 { transform: translateZ(-15rem) rotateX(180deg); } .cube.show-image-3 { transform: translateZ(-15rem) rotateY(-90deg); } .cube.show-image-4 { transform: translateZ(-15rem) rotateY(90deg); } .cube.show-image-5 { transform: translateZ(-15rem) rotateX(-90deg); } .cube.show-image-6 { transform: translateZ(-15rem) rotateX(90deg); } .image-buttons input { width: 104px; } .clickText{ margin-top: 150px; }</style> </head> <body> <div class="cube-container"> <div class="cube initial-position"> <img class="cube-face-image image-1" src="./images/1.jpg"> <img class="cube-face-image image-2" src="./images/2.jpg"> <img class="cube-face-image image-3" src="./images/3.jpg"> <img class="cube-face-image image-4" src="./images/4.jpg"> <img class="cube-face-image image-5" src="./images/5.jpg"> <img class="cube-face-image image-6" src="./images/6.jpg"> </div> </div> <h3 class="clickText">點(diǎn)擊下面的圖片來旋轉(zhuǎn)立方體</h3> <div class="image-buttons"> <input type="image" class="show-image-1" src="./images/1.jpg"></input> <input type="image" class="show-image-2" src="./images/2.jpg"></input> <input type="image" class="show-image-3" src="./images/3.jpg"></input> <input type="image" class="show-image-4" src="./images/4.jpg"></input> <input type="image" class="show-image-5" src="./images/5.jpg"></input> <input type="image" class="show-image-6" src="./images/6.jpg"></input> </div> </body> <script>//DOM load event window.addEventListener("DOMContentLoaded", () => { const cube = document.querySelector(".cube"), imageButtons = document.querySelector(".image-buttons"); let cubeImageClass = cube.classList[1]; //Add click event listener to image buttons container imageButtons.addEventListener("click", (e) => { //Get node type and class value of clicked element const targetNode = e.target.nodeName, targetClass = e.target.className; //Check if image input has been clicked and isn't the currently shown image if (targetNode === "INPUT" && targetClass !== cubeImageClass) { console.log(`Show Image: ${targetClass.charAt(11)}`); //Replace previous cube image class with new class cube.classList.replace(cubeImageClass, targetClass); //Update cube image class variable with new class cubeImageClass = targetClass; } }, false); }, false);</script> </html>
關(guān)于“如何使用HTML+CSS+JS制作3D立方體圖像庫”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“如何使用HTML+CSS+JS制作3D立方體圖像庫”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)站名稱:如何使用HTML+CSS+JS制作3D立方體圖像庫
網(wǎng)站鏈接:http://www.rwnh.cn/article26/jscscg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、外貿(mào)建站、網(wǎng)站維護(hù)、營銷型網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)