javascript - Sticky Nav with Header -
i've made nav sticky header shrinks little scroll
i'd have large image above nav user have scroll down, nav rise , stick in place. i'm having trouble finding tutorial. can point me in right direction?
function myscroll() { var header = document.getelementbyid("header"); var title = document.getelementbyid("title"); var ypos = window.pageyoffset; var nav = document.getelementbyid("mynav") if(ypos > 300) { header.style.height = "80px"; title.classlist.add("shrink"); nav.style.margintop = "25px"; } else { header.style.height = "150px"; title.classlist.remove("shrink"); nav.style.margintop = "90px"; } }; window.addeventlistener("scroll", myscroll);
* { margin: 0; padding:0; } #header { height: 150px; width: 100%; position: fixed; background-color: #f6f6f6; transition: .3s; z-index: 100; overflow: hidden; top:0; left: 0; } #title { margin-top: 50px; font-size: 50px; transition: .3s; float: left; } #title.shrink { font-size: 25px; margin-top: 25px; } nav { color: #aaa; float: right; margin-right: 20%; font-weight: 700; font-size: 1.4em; margin-top: 90px; transition: .3s; } #content { height: 2000px; border:1px solid #ccc; margin-top: 160px; width: 100%; }
<div id="header"> <h1 id="title">animated scroll</h1> <nav id="mynav"> <a href="">link 1</a> <a href="">link 1</a> <a href="">link 1</a> </nav> </div> <div id="content"></div>
Comments
Post a Comment