Sticky vaniila
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title></title> | |
| </head> | |
| <body> | |
| <header> | |
| <a href="#" class="logo">Logo</a> | |
| <ul> | |
| <li><a href="#">Home</a></li> | |
| <li><a href="#">About</a></li> | |
| <li><a href="#">Services</a></li> | |
| <li><a href="#">Portfolio</a></li> | |
| <li><a href="#">Team</a></li> | |
| <li><a href="#">Contact Us</a></li> | |
| </ul> | |
| </header> | |
| <section class="banner"></section> | |
| <script type="text/javascript"> | |
| window.addEventListener("scroll", function(){ | |
| var header = document.querySelector("header"); | |
| header.classList.toggle("sticky", window.scrollY > 0); | |
| } | |
| ) | |
| </script> | |
| </body> | |
| </html> | |
| <style type="text/css"> | |
| *{ | |
| margin: 0px; | |
| box-sizing: border-box; | |
| padding: 0px; | |
| font-family: arial; | |
| } | |
| body{ | |
| background: #000; | |
| min-height: 200vh; | |
| } | |
| header{ | |
| position: fixed; | |
| top: 0px; | |
| left: 0px; | |
| width: 100%; | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| transition: 0.6s; | |
| padding: 40px 100px; | |
| z-index: 10000000000000; | |
| } | |
| header.sticky{ | |
| padding: 5px 100px; | |
| background: #fff; | |
| } | |
| header.sticky ul li a{ | |
| color: #000; | |
| } | |
| header .logo{ | |
| position: relative; | |
| font-weight: 700; | |
| color: #fff; | |
| text-decoration: none; | |
| font-size: 2em; | |
| text-transform: uppercase; | |
| letter-spacing: 2px; | |
| transition: 0.6s; | |
| } | |
| header.sticky .logo{ | |
| color: #000; | |
| } | |
| header ul{ | |
| position: relative; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| } | |
| header ul li{ | |
| position: relative; | |
| list-style-type: none; | |
| } | |
| header ul li a{ | |
| position: relative; | |
| margin: 0 15px; | |
| text-decoration: none; | |
| color: #fff; | |
| letter-spacing: 2px; | |
| font-weight: 500; | |
| transform: 0.6s; | |
| } | |
| .banner{ | |
| position: relative; | |
| width: 100%; | |
| height: 100vh; | |
| background: url(img.jpg); | |
| background-size: cover; | |
| } | |
| </style> |
Comments
Post a Comment