다음은 CSS 및 JavaScript를 사용하여 커튼 탐색 메뉴를 만드는 코드입니다. −
예시
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> .sideNav { height: 100vh; width: 0; position: fixed; z-index: 1; top: 0; left: 0; background-color: rgba(46, 218, 195,0.4); overflow-x: hidden; padding-top: 60px; transition: 0.5s; } .sideNav a { padding: 8px 8px 8px 32px; text-decoration: none; font-size: 25px; color: #000000; font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; display: block; transition: 0.3s; text-align: center; } .sidenav a:hover { color: #f1f1f1; } .sideNav .closeBtn { position: absolute; top: 0; right: 25px; font-size: 36px; margin-left: 50px; } button { padding: 15px; background-color: rgb(0, 27, 145); color: rgb(255, 255, 255); font-size: 20px; border: none; border-radius: 2%; } </style> </head> <body> <nav class="sideNav"> <a href="#" class="closeBtn">×</a> <a href="#">Login</a> <a href="#">Register</a> <a href="#">Home</a> <a href="#">About Us</a> </nav> <button class="openSideNav">Click here to open sideNav</button> <div class="main-content"> <h1>Header One</h1> <p> Some paragraph text</p> <h2> Header Two</h2> <p> Some more paragraph text</p> </div> <script> let openBtn = document.querySelector(".openSideNav"); openBtn.addEventListener("click", () => { showNav(); }); let closeBtn = document.querySelector(".closeBtn"); closeBtn.addEventListener("click", () => { hideNav(); }); function showNav() { document.querySelector(".sideNav").style.width = "100%"; } function hideNav() { document.querySelector(".sideNav").style.width = "0"; } </script> </body> </html>
출력
위의 코드는 다음 출력을 생성합니다 -
sideNav 열기 버튼을 클릭하면 -