$(function(){ function nav_position(){ if($(window).width() > 767) { if($(window).scrollTop() > $('.header nav').height() + 233){ $('.horizontal_nav_background').slideDown(300); } else { $('.horizontal_nav_background').slideUp(300); if($('.horizontal_nav_background').css('display') === 'none'){ $('.horizontal_nav_background').css('display', ''); } } } } nav_position(); $(window).scroll(function(){ nav_position(); }); $(window).resize(function(){ nav_position(); }); $('.toggle_nav').on('click', function(){ if($('.horizontal_nav .nav_container').css('display') === 'none'){ $('.toggle_icon').attr('class', 'fa fa-times toggle_icon'); } else { $('.toggle_icon').attr('class', 'fa fa-bars toggle_icon'); } $('.horizontal_nav .nav_container').slideToggle(function(){ if($('.horizontal_nav .nav_container').css('display') === 'none'){ $('.horizontal_nav .nav_container').css('display', ''); } }); }); function change_image(){ current_header_image++; if(current_header_image >= header_images.length){ current_header_image = 0; } $(".header_transition").css("background-image", "url(" + header_images_path + header_images[current_header_image] + ")"); $(".header_transition").fadeIn(1000, function(){ $(".header_background").css("background-image", "url(" + header_images_path + header_images[current_header_image] + ")"); $(".header_transition").fadeOut(300); }); $(".horizontal_nav_background_transition").css("background-image", "url(" + header_images_path + header_images[current_header_image] + ")"); $(".horizontal_nav_background_transition").fadeIn(1000, function(){ $(".horizontal_nav_background").css("background-image", "url(" + header_images_path + header_images[current_header_image] + ")"); $(".horizontal_nav_background_transition").fadeOut(300); }); window.setTimeout(function(){change_image();}, interval); } var header_images_path = "img/environment/"; var header_images = ["background_blue.jpg", "background_red.jpg", "background_yellow.jpg"]; var interval = 10000; var current_header_image = Math.floor(Math.random()*header_images.length); $(".header_background").css("background-image", "url(" + header_images_path + header_images[current_header_image] + ")"); $(".horizontal_nav_background").css("background-image", "url(" + header_images_path + header_images[current_header_image] + ")"); window.setTimeout(function(){change_image();}, interval); });