Started from the bottom, now we're here.
This little bit of js and css makes it so that the 'back to the top' link will only go so far down on the page. It was born out of not wating the link to lay over the footer section.
// Adjust location of 'back to top' near the bottom of the page | |
function notTooNearTheBottom() { | |
var viewportHeight = $(window).height(); | |
var actionsArea = $(window).scrollTop() + viewportHeight; | |
var bottomBoundary = $(document).height() - 90; // this is our 'safe area' | |
if( actionsArea > bottomBoundary ) { | |
// console.log('near the bottom - move 'up to top', hide 'comments'); | |
$('#action-top').css('top', bottomBoundary); | |
} | |
else { | |
$('#action-top').css('top',''); //clear the inline css | |
} | |
} | |
// watch the scroll event | |
$(window).scroll(function(){ | |
//but - don't watch it too much. let's clear the timeout | |
clearTimeout(window.scroll_timeout); //.scroll_timeout is the variable | |
window.scroll_timeout = setTimeout(function() { | |
// function to call | |
notTooNearTheBottom(); | |
}, 20); // wait 'this long' to fire | |
}); |
#go-to-the-top { | |
top: 88%; // alternative to js - keeping it near the bottom | |
transition: top 250ms; // animate the transition | |
a:hover:after, a:active:after { // add nice label on hover | |
content: '\A top'; | |
font-size: 1.5rem; | |
white-space: pre; | |
vertical-align: top; | |
} | |
} |