forked from davist11/jQuery-One-Page-Nav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.nav.min.js
14 lines (14 loc) · 1.69 KB
/
jquery.nav.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
* jQuery One Page Nav Plugin
* http://github.com/davist11/jQuery-One-Page-Nav
*
* Copyright (c) 2010 Trevor Davis (http://trevordavis.net)
* Dual licensed under the MIT and GPL licenses.
* Uses the same license as jQuery, see:
* http://jquery.org/license
*
* @version 0.6
*/
(function(e){e.fn.onePageNav=function(j){var g=e.extend({},e.fn.onePageNav.defaults,j),c={};c.sections={};c.bindNav=function(b,d,a){var f=b.parent(),h=b.attr("href"),i=e(window);if(!f.hasClass(a.currentClass)){a.begin&&a.begin();c.adjustNav(d,f,a.currentClass);i.unbind(".onePageNav");e.scrollTo(h,a.scrollSpeed,{onAfter:function(){if(a.changeHash)window.location.hash=h;i.bind("scroll.onePageNav",function(){c.scrollChange(d,a.currentClass)});a.end&&a.end()}})}};c.adjustNav=function(b,d,a){b.find("."+
a).removeClass(a);d.addClass(a)};c.getPositions=function(b){b.find("a").each(function(){var d=e(this).attr("href"),a=e(d).offset();a=a.top;c.sections[d.substr(1)]=Math.round(a)})};c.getSection=function(b){var d="",a=Math.round(e(window).height()/2);for(var f in c.sections)if(c.sections[f]-a<b)d=f;return d};c.scrollChange=function(b,d){c.getPositions(b);var a=e(window).scrollTop();a=c.getSection(a);a!==""&&c.adjustNav(b,b.find("a[href=#"+a+"]").parent(),d)};c.init=function(b,d){b.find("a").bind("click",
function(f){c.bindNav(e(this),b,d);f.preventDefault()});c.getPositions(b);var a=false;e(window).bind("scroll.onePageNav",function(){a=true});setInterval(function(){if(a){a=false;c.scrollChange(b,d.currentClass)}},250)};return this.each(function(){var b=e(this),d=e.meta?e.extend({},g,b.data()):g;c.init(b,d)})};e.fn.onePageNav.defaults={currentClass:"current",changeHash:false,scrollSpeed:750,begin:false,end:false}})(jQuery);