-
Notifications
You must be signed in to change notification settings - Fork 11
/
offscreen.min.js
2 lines (2 loc) · 1.27 KB
/
offscreen.min.js
1
2
/*! Offscreen.js | (c) 2016 @gijsroge | MIT license | https://github.com/gijsroge/offscreen.js */
!function(a){a.fn.offscreen=function(b){var c={rightClass:"right-edge",leftClass:"left-edge",topClass:"top-edge",bottomClass:"bottom-edge",offset:0,smartResize:!0},b=a.extend(c,b),d=this;return this.offscreenInitiate=function(){a(d).each(function(){var b=a(window).width(),d=a(window).height(),e=a(this).offset().top,f=a(this).outerHeight();d<e+f?a(this).addClass(c.bottomClass):d>e+1.5*f&&a(this).removeClass(c.bottomClass),e<0?a(this).addClass(c.topClass):e>f&&a(this).removeClass(c.topClass);var g=a(this).offset().left,h=a(this).outerWidth()+c.offset;b<g+h?a(this).addClass(c.rightClass):a(this).removeClass(c.rightClass),g<0?a(this).addClass(c.leftClass):2*g>h&&a(this).removeClass(c.leftClass)})},this.offscreenInitiate(),!0===c.smartResize?(!function(a,b){var c=function(a,b,c){var d;return function(){function e(){c||a.apply(f,g),d=null}var f=this,g=arguments;d?clearTimeout(d):c&&a.apply(f,g),d=setTimeout(e,b||100)}};jQuery.fn[b]=function(a){return a?this.bind("resize",c(a)):this.trigger(b)}}(jQuery,"smartresize"),a(window).smartresize(function(){d.offscreenInitiate()})):a(window).resize(function(){d.offscreenInitiate()}),d.offscreenInitiate()},a("[data-offscreen]").offscreen()}(jQuery);