Prev/Next Links from Absolute to Fixed on Scroll
-
Hi everyone.
I got for my website’s #navigation that turns the bar from “position absolute” to “position: fixed” in my css file after x amount of scrolling
<SCRIPT type=”text/javascript”>
/* Handles the page being scrolled by ensuring the navigation is always in
* view.
*/
function handleScroll(){// check that this is a relatively modern browser
if (window.XMLHttpRequest){// determine the distance scrolled down the page
var offset = window.pageYOffset
? window.pageYOffset
: document.documentElement.scrollTop;// set the appropriate class on the navigation
document.getElementById(‘navigation’).className =
(offset > 240 ? ‘fixed’ : ”);
}}
// add the scroll event listener
if (window.addEventListener){
window.addEventListener(‘scroll’, handleScroll, false);
}else{
window.attachEvent(‘onscroll’, handleScroll);
}
</SCRIPT>with css:
#navigation {
top: 240px;
position: absolute;
padding: 15px 0px;
}#navigation.fixed {
position:fixed;
top: 0px;
background: white;
border-bottom: 1px dotted #d9d9d9;
}This works brilliantly, but I wanna expand it and have my navigation links to previous/next post/page (#nav-single, #nav-loop, #nav-search) to be to the bottom of the window to move whilst scrolling until after 50% of window is scrolled of pixels to turn it into fixed at that position (50% from top or bottom, whichever)
ive been playing around with the code for a good hour but I just cant seem to get it to work
please help??
- The topic ‘Prev/Next Links from Absolute to Fixed on Scroll’ is closed to new replies.