Difference between revisions of "Template:Team:TU Darmstadt/Js"

Line 10: Line 10:
 
       $('.navbar').addClass('top-fixed');
 
       $('.navbar').addClass('top-fixed');
 
       console.log('on top');
 
       console.log('on top');
     } else if ( $window.scrollTop() >= distance && $('.navbar').hasClass('top-fixed') ) {
+
     } else if ( $window.scrollTop() <= distance && $('.navbar').hasClass('top-fixed') ) {
 
       $('.navbar').removeClass('top-fixed');
 
       $('.navbar').removeClass('top-fixed');
 
     }
 
     }

Revision as of 10:02, 13 October 2016

// START MainMenu

$(window).load(function() {

 var distance = $('#title').outerHeight(),
 $window = $(window);
 console.log(distance);
 
 $window.scroll(function() {
   if ( $window.scrollTop() >= distance ) {
     $('.navbar').addClass('top-fixed');
     console.log('on top');
   } else if ( $window.scrollTop() <= distance && $('.navbar').hasClass('top-fixed') ) {
     $('.navbar').removeClass('top-fixed');
   }
 });

});

// END MainMenu // START ScrollBox

$(window).scroll(function(e) {

 var $element = $('.scrollbox');
 var headerHeight = $('#head').outerHeight();
 var isFixed = ($element.css('position') == 'fixed');
 if ($(this).scrollTop() > headerHeight) {
   if(!isFixed) {
       console.log('scroll');
       $element.addClass("scrolled");
   }
 }
 if ($(this).scrollTop() < headerHeight) {
   if(isFixed) {
       console.log('dont scroll');
       $element.removeClass("scrolled");
   }
 }

});

function scrollToTop() {

 $('body,html').animate({
   scrollTop: 0
 }, 400);

}

// END ScrollBox