Template:Team:Berkeley/topnav.js

From 2013.igem.org

(Difference between revisions)
(Created page with "var element = document.getElementById('navBar') window.addEventListener('scroll', function() { element.getBoundingClientRect().top < 0 ? element.classList.add('stuck')...")
 
(19 intermediate revisions not shown)
Line 1: Line 1:
-
var element = document.getElementById('navBar')
+
$(window).scroll(function () {
-
window.addEventListener('scroll', function() {
+
    if ($(window).scrollTop() > 289) {
-
    element.getBoundingClientRect().top < 0 ?
+
        $('#main-nav').css('top', $(window).scrollTop() - 289);
-
    element.classList.add('stuck') :
+
    }
-
    element.classList.remove('stuck');
+
    else {
-
});
+
        $('#main-nav').css('top', 0);
 +
    }
 +
}
 +
);

Latest revision as of 01:39, 28 October 2013

$(window).scroll(function () {

   if ($(window).scrollTop() > 289) {
       $('#main-nav').css('top', $(window).scrollTop() - 289);
   }
   else {
       $('#main-nav').css('top', 0);
   }

} );