Instagram-like nav (jQuery)

// All credits come from Chris Spittles // https://codepen.io/chrissp26/pen/gBrdo // I just adapted it to my own needs. var stickyHeaders = (function() { var $stickies; var load = function(stickies, target) { if (typeof stickies === "object" && stickies instanceof jQuery && stickies.length > 0) { $stickies = stickies.each(function() { var $thisSticky = $(this); $thisSticky .data('originalPosition', $thisSticky.offset().top) .data('originalHeight', $thisSticky.outerHeight()); }); target.off("scroll.stickies").on("scroll.stickies", function(event) { _whenScrolling(event); }); } }; var _whenScrolling = function(event) { var $scrollTop = $(event.currentTarget).scrollTop(); $stickies.each(function(i) { var $thisSticky = $(this), $stickyPosition = $thisSticky.data('originalPosition'), $newPosition, $nextSticky; if ($stickyPosition <= $scrollTop) { $newPosition = Math.max(0, $scrollTop - $stickyPosition); $nextSticky = $stickies.eq(i + 1); if($nextSticky.length > 0) { $newPosition = Math.min($newPosition, ($nextSticky.data('originalPosition') - $stickyPosition) - $thisSticky.data('originalHeight')); } } else { $newPosition = 0; } $thisSticky.css('transform', 'translate3d(0,' + $newPosition + 'px,0)'); }); }; return { load: load }; })(); $(function() { stickyHeaders.load($(".followMeBar"), $(window)); }); // styles // .followMeBar { // position: relative; // z-index: 9999999; // }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.