Skip to content

Instantly share code, notes, and snippets.

@jrodl3r
Created January 3, 2013 21:20
Show Gist options
  • Save jrodl3r/4447397 to your computer and use it in GitHub Desktop.
Save jrodl3r/4447397 to your computer and use it in GitHub Desktop.
Floating Scroll Title Menu
<script type="text/javascript">
$(document).ready(function () {
// Fixed-Scroll H2 Control Menu
var menuYloc = parseInt($('h2.floating-title').css('top'));
var menuOffset = 0;
$(window).scroll(function () {
// Fixed-Scroll H2 Control Menu (Logic)
if ($(document).scrollTop() > 200)
menuOffset = (menuYloc + $(document).scrollTop() - 240) + 'px';
else
menuOffset = (menuYloc + $(document).scrollTop()) + 'px';
if ($(document).scrollTop() >= 240)
$('h2.floating-title').addClass('pg-scrolled');
else if ($(document).scrollTop() < 200)
$('h2.floating-title').removeClass('pg-scrolled');
// Inject Return-to-Top Link
if ($(document).scrollTop() >= 800) {
if(!$('#return-to-top').length)
$("#floating-controller").append('<a id="return-to-top" href="#wrapper">Return to top</a>');
} else
$('#return-to-top').remove();
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment