Template:INSA-Lyon/javascript

/**


Custom JS

1. SCROLL TOP BUTTON 2. PRELOADER

       3. WOW

4. SIDEBAR

    • /

jQuery(function($){


/* ----------------------------------------------------------- */ /* 1. SCROLL TOP BUTTON /* ----------------------------------------------------------- */

//Check to see if the window is top if not then display button

$(window).scroll(function(){ if ($(this).scrollTop() > 300) { $('.scrollToTop').fadeIn(); } else { $('.scrollToTop').fadeOut(); } });

//Click event to scroll to top

$('.scrollToTop').click(function(){ $('html, body').animate({scrollTop : 0},800); return false; });

/* ----------------------------------------------------------- */ /* 2. PRELOADER /* ----------------------------------------------------------- */

jQuery(window).load(function() { // makes sure the whole site is loaded

     $('#status').fadeOut(); // will first fade out the loading animation
     $('#preloader').delay(100).fadeOut('slow'); // will fade out the white DIV that covers the website.
     $('body').delay(100).css({'overflow':'visible'});
   })
       /* ----------------------------------------------------------- */

/* 3. WOW ANIMATION /* ----------------------------------------------------------- */

wow = new WOW(

     {
       animateClass: 'animated',
       offset:       500,
       live:         true,
       callback:     function(box) {
         console.log("WOW: animating <" + box.tagName.toLowerCase() + ">")
       }
     }
   );
   wow.init(); 



   /* ----------------------------------------------------------- */

/* 4. SIDEBAR /* ----------------------------------------------------------- */

   //scroll to the right place clicking on the nav element
   var navOffset = $('.contents-sidebar').height();

$('.contents-sidebar li a').click(function(event) { var href = $(this).attr('href');

// Don't let the browser scroll, but still update the current address // in the browser. event.preventDefault(); window.location.hash = href;

// Explicitly scroll to where the browser thinks the element // is, but apply the offset. $(href)[0].scrollIntoView(); window.scrollBy(0, -navOffset); });


   //highlight the nav element dynamically
   $('body').scrollspy({
       target: '.contents-sidebar',
       offset: 200
   });
   if ($('#sidebar').length > 0) {
       $('#sidebar').affix({
           offset: {
               top: $('#sidebar').offset().top - 500,//make scrollspy think where the page is scrolled to
           }
       });
   }
   
   //show sidebar after image at the top
   $('#sidebar').hide();

$(window).scroll(function() {

   if ($(this).scrollTop() > 750)
    {
       var elmt = document.getElementById("sidebar");
       elmt.style.top='200px';
       $('#sidebar').fadeIn();
    }
   else
    {
     $('#sidebar').fadeOut();
    }
});

});