Create a gist now

Instantly share code, notes, and snippets.

@GaryJones /main.js Secret
Created Jul 14, 2014

What would you like to do?
Original Envy child theme main.js, by Jon Barratt
jQuery(document).ready(function($) {
// Responsive menu items:
$('.nav-header .genesis-nav-menu').before('<li class="menu-icon"></li>');
$(".menu-icon").on("click", function(){
$(".nav-header .genesis-nav-menu").slideToggle();
});
// Declare variables for heights:
var topnavHeight, sliderHeight, headerHeight
// Calculate variables and size of displacements:
$(window).on("load resize", function() {
// Menu reset before calculating heights:
$(".nav-header .genesis-nav-menu").hide();
// Assign values to variables:
topnavHeight = $(".nav-secondary").outerHeight() || 0;
sliderHeight = $(".slides li").outerHeight() || 0;
headerHeight = $(".site-header").height();
});
// Determine header position and displacements:
$(window).on("load scroll resize", function() {
var scrollYpos = $(document).scrollTop()
var windowWidth = $(window).width()
// Media query to detect slider onscreen for window size > 960 pixels:
if (windowWidth > 960 && $(".home-slider").length > 0 && scrollYpos < sliderHeight - 5) {
// Set displacements in flow:
$(".site-container").css('padding-top',topnavHeight);
$(".home-slider").css('margin-bottom',headerHeight);
// Unstick header and make header full height:
$(".site-header").addClass('unstuck').css('top',sliderHeight + topnavHeight);
$(".site-header .wrap").removeClass('narrow');
return false
} else {
// Set displacements in flow:
$(".site-container").css('padding-top',topnavHeight + headerHeight);
$(".home-slider").css('margin-bottom', 0);
// Make header sticky:
$(".site-header").removeClass('unstuck').css('top',topnavHeight);
// Make header narrow on scroll:
if (windowWidth > 960 && scrollYpos > 5) {
$(".site-header .wrap").addClass('narrow');
} else {
$(".site-header .wrap").removeClass('narrow');
}
}
});
// Fade out store notice soon after page load:
$(".demo_store").delay(4000).slideUp();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment