-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.scrolltracker.min.js
1 lines (1 loc) · 2.38 KB
/
jquery.scrolltracker.min.js
1
!function($){$.scrolltracker=function(e,o){$(window).on("DOMContentLoaded load resize scroll",function(){var n=$.extend({direction:"vertical"},o),t=function(e){return e.top>=0&&e.bottom<=(window.innerHeight||document.documentElement.clientHeight)?"onscreen":e.top>=(window.innerHeight||document.documentElement.clientHeight)||e.bottom<=0?"offscreen":e.top<0&&e.bottom>(window.innerHeight||document.documentElement.clientHeight)?"overflowing":e.top<0&&e.bottom>=0?"onfromtop":e.bottom>(window.innerHeight||document.documentElement.clientHeight)&&e.top<(window.innerHeight||document.documentElement.clientHeight)?"onfrombottom":void 0},i=function(e){return e.left>=0&&e.right<=(window.innerWidth||document.documentElement.clientWidth)?"onscreen":e.left>=(window.innerWidth||document.documentElement.clientWidth)||e.right<=0?"offscreen":e.left<0&&e.right>(window.innerWidth||document.documentElement.clientWidth)?"overflowing":e.left<0&&e.right>=0?"onfromleft":e.right>(window.innerWidth||document.documentElement.clientWidth)&&e.left<(window.innerWidth||document.documentElement.clientWidth)?"onfromright":void 0},r=function(e){return e.left>=0&&e.right<=(window.innerWidth||document.documentElement.clientWidth)&&e.top>=0&&e.bottom<=(window.innerHeight||document.documentElement.clientHeight)?"onscreen":e.left<0&&e.right>(window.innerWidth||document.documentElement.clientWidth)&&e.top<0&&e.bottom>(window.innerHeight||document.documentElement.clientHeight)?"overflowing":void 0};$(e).each(function(){var e=$(this),o=e[0].getBoundingClientRect();if("vertical"==n.direction||"both"==n.direction){var r=t(o);"onscreen"==r?e.addClass("onscreen_vert"):e.removeClass("onscreen_vert"),"offscreen"==r?e.addClass("offscreen_vert"):e.removeClass("offscreen_vert"),"overflowing"==r?e.addClass("overflowing_vert"):e.removeClass("overflowing_vert"),"onfromtop"==r?e.addClass("onfromtop"):e.removeClass("onfromtop"),"onfrombottom"==r?e.addClass("onfrombottom"):e.removeClass("onfrombottom")}if("horizontal"==n.direction||"both"==n.direction){var r=i(o);"onscreen"==r?e.addClass("onscreen_horiz"):e.removeClass("onscreen_horiz"),"offscreen"==r?e.addClass("offscreen_horiz"):e.removeClass("offscreen_horiz"),"overflowing"==r?e.addClass("overflowing_horiz"):e.removeClass("overflowing_horiz"),"onfromleft"==r?e.addClass("onfromleft"):e.removeClass("onfromleft"),"onfromright"==r?e.addClass("onfromright"):e.removeClass("onfromright")}})})}}(jQuery);