WebGL_0012:三維講解導航模板 Icon方式
阿新 • • 發佈:2020-08-10
1,
css樣式
/* 導航主按鈕 模板2 */ .iconElement { width: 50%; /* 高度等於 這個元素的寬度 * li元素的寬度 */ height: 2vw; text-align: center; display: inline-block; position: absolute; transform: translate(-50%,50%); bottom: 7%; left: 50%; /* background-color: red;*/ } .iconElement ul { display: flex; flex-direction: row; justify-content: center; /* background-color: yellow; */ } .iconElement ul li { display: inline-block; width: 4%; height: 0; padding: 4% 0 0; /* 設定icon之間的間距 */margin: 0 5%; /* background-color: seagreen; */ pointer-events: auto; } .icon0 { background-image: url("public/imgs/ui/iconN.png"); background-size: contain; background-position: center; background-repeat: no-repeat; } .icon0.active { background-image: url("public/imgs/ui/iconA.png"); } .icon1 { background-image: url("public/imgs/ui/iconN.png"); background-size: contain; background-position: center; background-repeat: no-repeat; } .icon1.active { background-image: url("public/imgs/ui/iconA.png"); } .icon2 { background-image: url("public/imgs/ui/iconN.png"); background-size: contain; background-position: center; background-repeat: no-repeat; } .icon2.active { background-image: url("public/imgs/ui/iconA.png"); } .icon3 { background-image: url("public/imgs/ui/iconN.png"); background-size: contain; background-position: center; background-repeat: no-repeat; } .icon3.active { background-image: url("public/imgs/ui/iconA.png"); }
2,html程式碼
<!-- 主導航按鈕模板2 --> <div class="PagebutDiv" style="display: block; "> <div class="leftButton" id="leftBtn" ondragstart="return!1" oncontextmenu="return!1" onselectstart="return!1"></div> <div class="iconElement pointEvtN"> <ul class="icon" id="icons"> <li class="iconBut active icon0" data="0"></li> <li class="iconBut icon1" data="1"></li> <li class="iconBut icon2" data="2"></li> <li class="iconBut icon3" data="3"></li> </ul> </div> <div class="rightButton" id="rightBtn" ondragstart="return!1" oncontextmenu="return!1" onselectstart="return!1"></div> </div>
JS程式碼
// 模板2左右按鈕點選響應事件 UieventControl.prototype.changePage2 = function(e) { if (canclick) { console.log("112232"); //通過click獲取物件的ID "rightBtn" === e.currentTarget.id ? currentPage++ : currentPage--; totalPage < currentPage ? currentPage = 0 : currentPage < 0 && (currentPage = totalPage); // 修改按鈕樣式 PageButID = "icon" + currentPage; console.log(PageButID); $addAcByID(".iconBut", PageButID); } };