File: D:/HostingSpaces/SBogers75/roost-interieurbouw.nl/wwwroot/js/animations.js
/**
* Created by Pascal on 17/11/15.
*/
/**
* Created by Pascal on 29/10/15.
*/
var keys = {37: 1, 38: 1, 39: 1, 40: 1}; //scroll keys
$(function() {
$('.intro').removeClass('intro');
$logoOffset =$('.logo .sub-header').offset();
$widthWindow = $(window).width();
$additionalOffset = 80;
if($widthWindow<=1200){
$additionalOffset = 60;
}
if($widthWindow<=700){
$additionalOffset = 40;
}
if($widthWindow<=500){
$additionalOffset = 25;
}
setTimeout(function() {
$(".sub-header").hide();
}, 3500);
setTimeout(function() {
$('.logo').addClass('no-after-animations');
$('.top-bar').addClass('no-after-animations');
$('.yellow-bar').addClass('no-after-animations');
setInterval(homePageSlider,5000);
}, 2500);
$imageCounter = 1;
$('.bottom-bar').css('bottom', ($logoOffset.top-$additionalOffset)*-1);
$(window).scroll(function () {
//$('.parallax').css('background-position', '0% '+ (100 - $(document).scrollTop()/$(document).height()*100)+'%');
if($(document).scrollTop()<=100){
$('.top-bar').removeClass('small');
$('header .logo').removeClass('small');
$('header .yellow-bar').removeClass('small');
}
else{
$('.top-bar').addClass('small');
$('header .logo').addClass('small');
$('header .yellow-bar').addClass('small');
}
if(isElementInViewport($('#home'))){ //menu item in view
$('nav .active').removeClass('active');
$('nav .home-item').addClass('active');
}
if(isElementInViewport($('#about-us'))){ //menu item in view
$('nav .active').removeClass('active');
$('nav .about-item').addClass('active');
}
if(isElementInViewport($('#reference'))){ //menu item in view
$('nav .active').removeClass('active');
$('nav .references-item').addClass('active');
$('.blank-background').show();
$('.border-animation-right').removeClass('not-in-view');
$('.border-animation-down').removeClass('not-in-view');
$('.border-animation-left').removeClass('not-in-view');
}
if(isElementInViewport($('#partner'))){ //menu item in view
$('nav .active').removeClass('active');
$('nav .partners-item').addClass('active');
}
if(isElementInViewport($('#product1'))){ //menu item in view
$('nav .active').removeClass('active');
$('nav .products-item').addClass('active');
$('.blank-background').show();
}
if(isElementInViewport($('#contact'))){ //menu item in view
$('nav .active').removeClass('active');
$('nav .contact-item').addClass('active');
}
if(isElementInViewport($('#history'))){
$('.history-dimension').removeClass('not-in-view'); //slide in history dimension
}
if(isElementInViewport($('.intro-text'))){
$('.about-row .placeholder').removeClass('not-in-view'); //enlarge about placeholder
}
if(isElementInViewport($('.about-row .red-divider'))){ //animate red border
$('.red-divider').removeClass('not-in-view');
}
if(isElementInViewport($('.partners'))){ //animate red border
$('.partners').removeClass('not-in-view');
$('.blank-background').show();
}
if(isElementInViewport($('#history'))){
$('.blank-background').hide();
}
if(isElementInViewport($('.red-divider'))){
$('.blank-background').show();
}
});
function elementInViewport(el) {
if ( $(el).length ) {
if (isElementInViewport(el)) {
el.addClass('active');
}
else {
el.removeClass('active');
}
}
}
function elementInViewportOnce(el) {
if ( $(el).length ) {
if (isElementInViewport(el)) {
el.addClass('active');
}
}
}
function isElementInViewport(el) {
if ( $(el).length ) {
//special bonus for those using jQuery
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.bottom <= (window.innerHeight || $(window).height())
);
}
}
function homePageSlider(){
if($imageCounter == $('.home-slider').length){
$('.home-slider').removeClass('active');
$imageCounter = 1;
}
else {
$imageCounter++;
$('.home-slider.background' + $imageCounter).addClass('active');
}
}
});