Last active
December 22, 2018 11:24
-
-
Save muthu32/ca90456b83e2e4a41bde36901bdb08b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| document.getElementById("header").style.top = 0; | |
| var prevScrollpos = window.pageYOffset; | |
| window.onscroll = function() { | |
| document.getElementById("header").style.position = 'fixed'; | |
| var currentScrollPos = window.pageYOffset; | |
| var htop = parseInt(document.getElementById("header").style.top); | |
| var menuHeight = $('header').outerHeight()+5; | |
| if (prevScrollpos > currentScrollPos) { | |
| htop = htop +3; | |
| console.log("Top"+ htop); | |
| if(htop<=0) | |
| document.getElementById("header").style.top = htop+"px"; | |
| } else { | |
| htop = htop -3; | |
| console.log("Bottom"+ htop); | |
| if(htop<0 && htop>-menuHeight) | |
| { | |
| document.getElementById("header").style.top = htop+"px"; | |
| } | |
| } | |
| prevScrollpos = currentScrollPos; | |
| } | |
| //Standard Method | |
| document.getElementById("header").style.top = 0; | |
| var menuHeight = $('header').outerHeight()+5; | |
| document.getElementById("block").style.paddingTop = menuHeight+"px"; | |
| var prevScrollpos = window.pageYOffset; | |
| window.scrolldir = 1; | |
| window.onscroll = function() { | |
| document.getElementById("header").style.position = 'fixed'; | |
| var currentScrollPos = window.pageYOffset; | |
| var htop = parseInt(document.getElementById("header").style.top); | |
| if(scrolldir<-25 || scrolldir>150) | |
| scrolldir = 1; | |
| if (prevScrollpos > currentScrollPos) { | |
| htop = htop +3; | |
| scrolldir = scrolldir+3; | |
| console.log("Top"+ htop); | |
| if(scrolldir>145) | |
| document.getElementById("header").style.top = "0px"; | |
| } else { | |
| scrolldir = scrolldir-3; | |
| htop = htop -3; | |
| console.log("Bottom"+ htop); | |
| if(scrolldir<-20) | |
| { | |
| document.getElementById("header").style.top = -window.menuHeight+"px"; | |
| } | |
| } | |
| prevScrollpos = currentScrollPos; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment