(function($) { "use strict"; $.fn.ScrollNav = function(options, args) { var defaults = { topSpacing: "nav", addActiveClass: false, externalLinkSelector: false, watchScroll: false, scrollSpeed: 500, watchUrlChange: false, relAttr: "data-scroll-rel", clickCallBack: function() { } }; if (options === "defaults") { return defaults; } var Opt = $.extend(defaults, options); var SN = new $.ScrollNav(Opt, $(this), arguments); SN.init(); return this; } $.ScrollNav = function(Opt, $scopeEl, allArgs) { var me = this; var $Items = false; var scrollAnimationActive = false; var voidHashChange = false; var elements = {}; this.init = function() { $Items = $scopeEl; if (Opt.externalLinkSelector !== false) { $Items = $scopeEl.not(Opt.externalLinkSelector); } me.cache(); $Items.click(function(e) { var $el = $(this); me.doScroll($el); me.redirect($el.data("scrollNav-targetStr")); e.preventDefault(); return false; }); me.watchScroll(); $(window).resize(function() { me.cache(); }); if (Opt.watchUrlChange === true) { $(window).on('hashchange', function(e) { if (!voidHashChange) { me.detectHash(); e.preventDefault(); } voidHashChange = false; }); me.detectHash(true); } } this.detectHash = function(onLoad) { voidHashChange = true; if (Opt.watchUrlChange === true) { if (window.location.hash && elements[window.location.hash]) { me.doScroll(elements[window.location.hash]); } } } this.parseTopSpacing = function(spcaing) { if (typeof spcaing == "undefined") { if (typeof Opt.topSpacing == "function") { return me.parseTopSpacing(Opt.topSpacing()); } else { return me.parseTopSpacing(Opt.topSpacing); } } else { if (parseInt(spcaing) > 0) { return parseInt(spcaing); } else { return $(spcaing).height(); } } } this.cache = function() { $Items.each(function(e) { var $el = $(this); var targetStr = $el.attr("href"); elements[targetStr] = $el; //$el.attr("href", "javascript:void(0)"); var $target = $("[" + Opt.relAttr + "='" + targetStr.replace("#", "") + "']"); $el.data("scrollNav-target", $target); $el.data("scrollNav-targetStr", targetStr); $el.data("scrollNav-topSpacing", me.parseTopSpacing()); $el.data("scrollNav-targetOffset", $target.offset()) $el.data("scrollNav-targetOuterHeight", $target.outerHeight(true)) }); } this.doScroll = function($el) { var targetStr = $el.data("scrollNav-targetStr"); var $target = $el.data("scrollNav-target"); scrollAnimationActive = true; if (Opt.addActiveClass !== false) { $Items.removeClass(Opt.addActiveClass); $el.addClass(Opt.addActiveClass); } var topSpacing = $el.data("scrollNav-topSpacing"); var offsetTop = $target.offset().top - topSpacing; offsetTop = (offsetTop = 0) { found = targetStr; $Items.removeClass(Opt.addActiveClass); $el.addClass(Opt.addActiveClass); me.redirect(targetStr); } }); if (!found) { $Items.removeClass(Opt.addActiveClass); } } }) } } } })(jQuery);


https://www.iVisa.com