Team:DTU-Denmark/StickyNav.js
From 2014.igem.org
(Difference between revisions)
Tbjohannesen (Talk | contribs) (Created page with " //STICKY NAV $(document).ready(function () { var top = $('#nav').offset().top - parseFloat($('#nav').css('marginTop').replace(/auto/, 100)); $(window).scroll(function (eve...") |
Tbjohannesen (Talk | contribs) |
||
Line 1: | Line 1: | ||
- | |||
//STICKY NAV | //STICKY NAV | ||
$(document).ready(function () { | $(document).ready(function () { | ||
- | var top = $('#nav').offset().top - parseFloat($('#nav').css('marginTop').replace(/auto/, | + | var top = $('#nav').offset().top - parseFloat($('#nav').css('marginTop').replace(/auto/, 500)); |
$(window).scroll(function (event) { | $(window).scroll(function (event) { | ||
// what the y position of the scroll is | // what the y position of the scroll is |
Latest revision as of 11:09, 24 July 2014
//STICKY NAV $(document).ready(function () {
var top = $('#nav').offset().top - parseFloat($('#nav').css('marginTop').replace(/auto/, 500)); $(window).scroll(function (event) { // what the y position of the scroll is var y = $(this).scrollTop();
// whether that's below the form if (y >= top) { // if so, ad the fixed class $('#nav').addClass('fixed'); } else { // otherwise remove it $('#nav').removeClass('fixed'); } });
});