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

(Created page with "<js template>")
 
Line 1: Line 1:
<js template>
+
$(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);
 +
}

Revision as of 12:14, 12 October 2016

$(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);

}