-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-sticky.min.js
1 lines (1 loc) · 1.55 KB
/
angular-sticky.min.js
1
!function(s){"use strict";var e=["$compile","$timeout","$window",function(e,i,t){return{restrict:"A",scope:{scrollingElem:"=?",superSticky:"=?",css:"=?",listenResize:"=?"},link:function(e,c){i(function(){var i,l=!1,n=c.css("display"),o=c.css("position"),d=c.css("top"),f=c.css("left"),r=c.css("width"),p=e.scrollingElem||document;c.addClass("sticky"),e.superSticky&&c.addClass("sticky-keep-visible"),e.listenResize&&s.element(t).on("resize",function(){l&&(c.css("width",e.listenResize.offsetWidth+"px"),i.css("width",e.listenResize.offsetWidth+"px"),r&&(r=e.listenResize.offsetWidth+"px"))}),s.element(p).on("scroll",function(){var e=l?i:c,t=e[0].getBoundingClientRect().top,p=0;if(s.forEach(s.element(document.querySelectorAll(".sticky.sticky-is-visible.sticky-keep-visible")),function(s){s!==c[0]&&s.offsetWidth>0&&s.offsetHeight>0&&(p+=s.offsetHeight)}),p>=t)l||(i=s.element("<div></div>"),i.css("width",c[0].offsetWidth+"px"),i.css("height",c[0].offsetHeight+"px"),c.after(i),s.element(document.querySelectorAll(".sticky.sticky-is-visible:not(.sticky-keep-visible)")).css("display","none"),c.css("width",c[0].offsetWidth+"px"),c.css("position","fixed"),c.css("top",p+"px"),c.css("left","0px"),c.addClass("sticky-is-visible"),l=!0);else if(i){i.remove(),c.css("width",r),c.css("display",n),c.css("position",o),c.css("top",d),c.css("left",f),c.removeClass("sticky-is-visible"),l=!1;var y=s.element(document.querySelectorAll(".sticky.sticky-is-visible"));y.length>0&&s.element(y[y.length-1]).css("display",n)}})})}}}];s.module("ngSticky",[]).directive("ngSticky",e)}(window.angular);