$(function() {
// Our menu to clone
var stickyDiv = $('.js-sticky-container');
// Class with fixed positioning
var posFixed = 'js-sticky-fixed';
// Product menu's offset from top window
var menuTop = stickyDiv.offset().top;
// Clone the product menu, and add the fixed class
var menuClone = stickyDiv.clone(true).addClass(posFixed);
$('#js-product-menu li').each(function(index, value) {
var newIndex = index + 1;
$(this).attr('id', 'js-product-' + newIndex);
});
$('#js-current-products .js-current-product').each(function(index, value) {
var newIndex = index + 1;
$(this).attr('id', 'js-current-product-' + newIndex);
});
var productPosition = function() {
$('.js-current-product').each(function(index, value) {
// start at a base index of 1 instead of 0
var newIndex = index + 1;
// Get offset (minus a 500px buffer) of the product image
var currentProduct = $(this).offset().top - 500;
if (scrollY > currentProduct) {
$('#js-product-menu li').removeClass('selected');
$('#js-product-' + newIndex).addClass('selected');
}
});
};
// This basically clones the div surrounded by `.js-sticky-container` and adds a
// class with a fixed position on it to "stick"
var stickyContainer = function(stickyDiv, posFix, clonedWidth) {
// Use the original container width
if (clonedWidth === undefined) {
clonedWidth = $(stickyDiv).width();
}
$(window).bind('scroll', function() {
// Check position of the product image and add the class to the nav menu
// if the corresponding image fits the product name
productPosition();
// What the current px is from vertical scroll
var scrollY = window.pageYOffset;
// They scrolled more than the original offset
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.