-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.superSticky.min.js
1 lines (1 loc) · 6.98 KB
/
jquery.superSticky.min.js
1
(function(a){a.fn.superSticky=function(b){var c={init:function(b){return this.superSticky.settings=a.extend({},this.superSticky.defaults,b),this.each(function(){var b=a(this),c=this;if(b.superSticky.settings.wrapper===void 0)var e=b.parent();else{var e=a(b.superSticky.settings.wrapper);b.superSticky.settings.wrapper}var g={targetInitialPosition:b.css("position"),targetInitialTop:b.css("top"),targetInitialTopOffset:b.offset().top,targetInitialWrapperOffset:b.offset().top-e.offset().top,pageScrollElementBottomFlag:!1,lastScrollTop:0,freezePositionFlag:!1,targetInitialLeftOffset:b.offset().left};console.log(g.targetInitialPosition),g.targetInitialPosition="static",b.superSticky.settings.padding_top>g.targetInitialTopOffset&&(b.superSticky.settings.padding_top=g.targetInitialTopOffset),d.scroll(c,g),a(window).scroll(function(){d.scroll(c,g)}),b.mutate("height",function(){d.scroll(c,g)}),e.mutate("height",function(){d.scroll(c,g),console.log("wrapper height change")})})}},d={scroll:function(b,c){var d=a(b);if(d.superSticky.settings.wrapper===void 0)var f=d.parent();else{var f=a(d.superSticky.settings.wrapper);d.superSticky.settings.wrapper}c.scrollPosition=a(window).scrollTop(),c.targetPosition=d.offset().top,c.windowHeight=a(window).outerHeight(),c.targetHeight=d.outerHeight(),c.wrapperHeight=f.outerHeight(),c.wrapperPosition=f.offset().top;var h=function(){d.css("position",c.targetInitialPosition),d.css("top",c.targetInitialTop),d.css("left","auto")},i=function(){d.css("position","relative"),d.css("top",c.wrapperHeight-d.superSticky.settings.padding_bottom-c.targetInitialWrapperOffset-c.targetHeight),d.css("left","auto")},j=function(){d.css("position","fixed"),d.css("top",d.superSticky.settings.padding_top),c.freezePositionFlag=!1,d.css("left",c.targetInitialLeftOffset)},k=function(){d.css("position","fixed"),d.css("top",c.windowHeight-(c.targetHeight+d.superSticky.settings.padding_bottom)),c.freezePositionFlag=!1,d.css("left",c.targetInitialLeftOffset)},l=function(){d.css("position","relative"),c.freezePositionFlag||(c.freezePositionFlag=c.targetPosition-c.targetInitialTopOffset,d.css("top",c.freezePositionFlag),d.css("left","auto"))},m=function(){d.css("position",c.targetInitialPosition),d.css("top",c.targetInitialTop),d.css("left","auto")};c.targetInitialTopOffset+d.superSticky.settings.padding_bottom+c.targetHeight-c.wrapperPosition<c.wrapperHeight?c.scrollPosition<=c.targetInitialTopOffset-d.superSticky.settings.padding_top?h():c.windowHeight<=c.targetHeight+d.superSticky.settings.padding_top+d.superSticky.settings.padding_bottom?(c.scrollPosition+c.targetHeight-(c.targetHeight+d.superSticky.settings.padding_bottom-c.windowHeight)>=c.wrapperHeight+c.wrapperPosition-d.superSticky.settings.padding_bottom?i():c.scrollPosition>c.lastScrollTop?c.scrollPosition>=c.targetPosition+(c.targetHeight+d.superSticky.settings.padding_bottom-c.windowHeight)?(c.pageScrollElementBottomFlag=!0,k()):l():c.scrollPosition<=c.targetPosition-d.superSticky.settings.padding_top&&c.pageScrollElementBottomFlag?j():l(),c.lastScrollTop=c.scrollPosition):c.scrollPosition+c.targetHeight+d.superSticky.settings.padding_top>=c.wrapperHeight+c.wrapperPosition-d.superSticky.settings.padding_bottom?i():j():m()}};return c[b]?c[b].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof b&&b?(a.error('Method "'+b+'" does not exist in the superSticky plugin!'),void 0):c.init.apply(this,arguments)},a.fn.superSticky.defaults={padding_top:0,padding_bottom:0},a.fn.superSticky.settings={}})(jQuery),mutate_event_stack=[{name:"width",handler:function(a){return n={el:a},$(n.el).data("mutate-width")||$(n.el).data("mutate-width",$(n.el).width()),$(n.el).data("mutate-width")&&$(n.el).width()!=$(n.el).data("mutate-width")?($(n.el).data("mutate-width",$(n.el).width()),!0):!1}},{name:"height",handler:function(a){return element=a,$(element).data("mutate-height")||$(element).data("mutate-height",$(element).height()),$(element).data("mutate-height")&&$(element).height()!=$(element).data("mutate-height")?($(element).data("mutate-height",$(element).height()),!0):void 0}},{name:"top",handler:function(a){return $(a).data("mutate-top")||$(a).data("mutate-top",$(a).css("top")),$(a).data("mutate-top")&&$(a).css("top")!=$(a).data("mutate-top")?($(a).data("mutate-top",$(a).css("top")),!0):void 0}},{name:"bottom",handler:function(a){return $(a).data("mutate-bottom")||$(a).data("mutate-bottom",$(a).css("bottom")),$(a).data("mutate-bottom")&&$(a).css("bottom")!=$(a).data("mutate-bottom")?($(a).data("mutate-bottom",$(a).css("bottom")),!0):void 0}},{name:"right",handler:function(a){return $(a).data("mutate-right")||$(a).data("mutate-right",$(a).css("right")),$(a).data("mutate-right")&&$(a).css("right")!=$(a).data("mutate-right")?($(a).data("mutate-right",$(a).css("right")),!0):void 0}},{name:"left",handler:function(a){return $(a).data("mutate-left")||$(a).data("mutate-left",$(a).css("left")),$(a).data("mutate-left")&&$(a).css("left")!=$(a).data("mutate-left")?($(a).data("mutate-left",$(a).css("left")),!0):void 0}},{name:"hide",handler:function(a){return $(a).is(":hidden")?!0:void 0}},{name:"show",handler:function(a){return $(a).is(":visible")?!0:void 0}},{name:"scrollHeight",handler:function(a){return $(a).data("prev-scrollHeight")||$(a).data("prev-scrollHeight",$(a)[0].scrollHeight),$(a).data("prev-scrollHeight")&&$(a)[0].scrollHeight!=$(a).data("prev-scrollHeight")?($(a).data("prev-scrollHeight",$(a)[0].scrollHeight),!0):void 0}},{name:"scrollWidth",handler:function(a){return $(a).data("prev-scrollWidth")||$(a).data("prev-scrollWidth",$(a)[0].scrollWidth),$(a).data("prev-scrollWidth")&&$(a)[0].scrollWidth!=$(a).data("prev-scrollWidth")?($(a).data("prev-scrollWidth",$(a)[0].scrollWidth),!0):void 0}},{name:"scrollTop",handler:function(a){return $(a).data("prev-scrollTop")||$(a).data("prev-scrollTop",$(a)[0].scrollTop()),$(a).data("prev-scrollTop")&&$(a)[0].scrollTop()!=$(a).data("prev-scrollTop")?($(a).data("prev-scrollTop",$(a)[0].scrollTop()),!0):void 0}},{name:"scrollLeft",handler:function(a){return $(a).data("prev-scrollLeft")||$(a).data("prev-scrollLeft",$(a)[0].scrollLeft()),$(a).data("prev-scrollLeft")&&$(a)[0].scrollLeft()!=$(a).data("prev-scrollLeft")?($(a).data("prev-scrollLeft",$(a)[0].scrollLeft()),!0):void 0}}],function(a){function b(){var c=mutate;"undefined"!=c.event_stack&&c.event_stack.length&&a.each(c.event_stack,function(a,b){mutate.add_event(b)}),c.event_stack=[],a.each(c.stack,function(b,d){a(d.selector).each(function(a,b){c.events[d.event_name](b)===!0?d.callback&&d.callback(b,d):d.false_callback&&d.false_callback(b,d)})}),setTimeout(b,mutate.speed)}mutate={speed:1,event_stack:mutate_event_stack,stack:[],events:{},add_event:function(a){mutate.events[a.name]=a.handler},add:function(a,b,c,d){mutate.stack[mutate.stack.length]={event_name:a,selector:b,callback:c,false_callback:d}}},b(),a.fn.extend({mutate:function(){var b=!1,c=arguments[1],d=this,e=arguments[2]?arguments[2]:function(){};return"extend"==arguments[0].toLowerCase()?(mutate.add_event(c),this):(a.each(a.trim(arguments[0]).split(" "),function(a,f){b=f,mutate.add(b,d,c,e)}),this)}})}(jQuery);