1 line
1.3 KiB
JavaScript
1 line
1.3 KiB
JavaScript
|
!function(i,t,e,n){i.fixed=function(e,s){var a={topSpace:0,placeholder:!0,onFixed:function(){},onStatic:function(){}},o=this;o.settings={};var c,l,d,e=(i(e),e);o.init=function(){o.settings=i.extend({},a,s),i(e).wrap("<div class='navigation-fixed-wrapper'></div>").each(function(){c=i(e).parent(),o.settings.placeholder&&(i("<div class='navigation-fixed-placeholder'></div>").insertBefore(c),i(".navigation-fixed-placeholder").css("height",i(c).outerHeight()),l=i(".navigation-fixed-placeholder"))}),d=i(c).offset().top,d<=o.settings.topSpace?f():i(t).on("scroll",function(){i(t).scrollTop()>=d-o.settings.topSpace?i(c).hasClass("fixed")||f():i(c).hasClass("fixed")&&r()}),i(t).resize(function(){h(),o.settings.placeholder&&i(l).css("height",i(c).outerHeight())}),i(e).on("click touchstart",function(){h()})};var f=function(){i(c).addClass("fixed"),o.settings.placeholder&&i(l).addClass("visible"),h(),s!==n&&o.callback("onFixed")},r=function(){i(c).removeClass("fixed"),o.settings.placeholder&&i(l).removeClass("visible"),s!==n&&o.callback("onStatic")},h=function(){i(e).css("width",i(c).parent().width()),i(c).css("top",o.settings.topSpace)};o.callback=function(i){s[i]!==n&&s[i].call(e)},o.init()},i.fn.fixed=function(t){return this.each(function(){if(n==i(this).data("fixed")){var e=new i.fixed(this,t);i(this).data("fixed",e)}})}}(jQuery,window,document);
|