我使用 gsap.js 作為彈出視窗/模式。我使用 forEach,這樣無論我添加這個網站有多少相同的部分,它都會正常工作。我唯一的目標是現在,以某種方式完美地完成這項工作。每當您單擊彈出的“按鈕”時,我就會出現,然後您會得到9 個圖像,並從中選擇4 個圖像,然後單擊“保存編輯”,當您按“保存編輯”然後是正文圖像時,其中有4 個圖像身體,它會自動改變。並且您可以一次又一次地更改它。
const items = document.querySelectorAll(".mdlsc"); const modal = document.querySelector(".modal"); items.forEach((item, index) => { item.querySelector(".opnBtn").addEventListener("click", () => { item.querySelector(".modal").style.display = "grid"; gsap.to(item.querySelector(".modalwrap"), { scale: 1, ease: "elastic.out(1, 0.3)", }); }); item.querySelector(".ovlybg").addEventListener("click", () => { gsap.to(item.querySelector(".modalwrap"), { scale: 0, ease: "elastic.out(1, 0.3)", }); item.querySelector(".modal").style.display = "none"; }); });
body { width: 100%; overflow-x: hidden; color: #fff; background: url(https://polite-figolla-02d41d.netlify.app/img/wefdf.png) no-repeat; background-size: cover; background-position: center center; height: 100vh; } body img { width: 100%; } body button { background: transparent; border: none; cursor: pointer; } .main { width: 500px; margin: auto; } .modal { position: fixed; z-index: 9; left: 0%; top: 0%; width: 100%; height: 100vh; place-content: center; place-items: center; display: none; } .modal .ovlybg { position: absolute; background: rgba(0, 0, 0, 0.5); top: 0px; left: 0%; z-index: 1; width: 100%; height: 100%; } .modal .modalwrap { transform: scale(0); width: 400px; margin: auto; height: -webkit-fit-content; height: -moz-fit-content; height: fit-content; border: 5px solid #fff; border-radius: 77px; position: relative; z-index: 3; background: linear-gradient(to right, #400df0, #6203b3, #940599); text-align: center; text-transform: uppercase; font-weight: 600; padding: 45px 0px; } .edtchp { text-align: center; padding: 25px 0px 2px; } .edtchp span { font-size: 1em; margin: 0; } .edtchp h1 { font-size: 2.2em; color: #fff; margin: 0; transform: translate(0px, 0px); } .clsebtn img { width: 120px; } .mdlsc { margin-left: 10px; } .grypnk { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 18px 5px; width: 80%; margin: auto; } .grypnk img { width: 100% !important; } .coinsc { display: flex; align-items: center; width: 85%; margin: auto; gap: 8px; justify-content: center; margin: 10px auto; } .coinsc .imdwidth { display: flex; align-items: center; } .coinsc .imdwidth img { width: 45px; } .coin { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; align-items: center; }
<div class="main"> <div class="coinsc"> <div class="coin"> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-100.png" alt="" /> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-500.png" alt="" /> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-1000.png" alt="" /> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-3000.png" alt="" /> </div> <div class="mdlsc"> <div class="modal"> <div class="modalwrap antclr"> <div class="edtchp"> <h1>Edit Chip Rack</h1> <span>SELECT 4 CHIPS TO DISPLAY</span> </div> <div class="grypnk"> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-1.png" alt="" /> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-50.png" alt="" /> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-1000.png" alt="" /> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-5.png" alt="" /> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-100.png" alt="" /> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-3000.png" alt="" /> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-10.png" alt="" /> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-500.png" alt="" /> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-5000.png" alt="" /> </div> <a href="#" class="clsebtn" > <img src="https://polite-figolla-02d41d.netlify.app/img/saveedit.png" alt="" /> </a> </div> <div class="ovlybg"></div> </div> <button class="opnBtn"> <div class="imdwidth"> <img src="https://polite-figolla-02d41d.netlify.app/img/Chips/chip-editchip.png" alt="" /> </div> </button> </div> </div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.3/gsap.min.js"></script>
這是我的方法。在開發這個解決方案時,GsapJS 函式庫並不是一個障礙。您會看到我已經單獨發布了圖像,因為您的圖像已自動取消發布。
除非您儲存,否則您的變更將不會顯示。用戶在這裡選擇的晶片數量是 4。每當您嘗試選擇更多或儲存編輯但未選擇至少 4 個晶片時,它都會向您發出警報。因此,在選擇新晶片之前,您必須取消選擇灰色晶片。我在這裡使用了術語“晶片”而不是“硬幣”。
我使用的工具是 CSS 動畫,讓點擊後的晶片看起來像翻轉一樣。這些材料/來源對我的工作有幫助,
w3school
#bobbyhadz