-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.scrollIn.min.js
More file actions
1 lines (1 loc) · 3.3 KB
/
jquery.scrollIn.min.js
File metadata and controls
1 lines (1 loc) · 3.3 KB
1
!function(o){"function"==typeof define&&define.amd?define(["jquery"],o):"object"==typeof module&&module.exports?module.exports=o(require("jquery")):o(window.jQuery)}(function(o){var r={behavior:"auto",block:"start",margin:0,lazy:!1};o.fn.scrollIn=function(l){!0===l?l={block:"start"}:!1===l?l={block:"end"}:"object"!=typeof l&&(l={}),l=o.extend({},r,l),l.behavior={auto:200,smooth:400}[l.behavior]||parseInt(l.behavior)||1;var i=this.first(),t=i.parent().closest(":scrollable"),c={options:{easing:"linear",duration:l.behavior,queue:"scrollIn"}};return t.length&&(o.each(e,function(o,r){var e;if(t.prop(r.scrollDim)>t.prop(r.clientDim)&&(e=i.offset()[r.cor]-t.offset()[r.cor]+t[r.scrollCor](),!l.lazy||t[r.scrollCor]()>e-l.margin||e+l.margin+i[r.outerDim]()>t[r.scrollCor]()+t.prop(r.clientDim))){switch(l.block){case"end":c[r.scrollCor]=e+l.margin-(t.prop(r.clientDim)-i[r.outerDim]());break;case"middle":c[r.scrollCor]=e-l.margin-(t.prop(r.clientDim)-i[r.outerDim]())/2;break;default:c[r.scrollCor]=e-l.margin}c[r.scrollCor]=Math.max(0,Math.min(t.prop(r.scrollDim)-t.prop(r.clientDim),c[r.scrollCor]))}}),(void 0!==c.scrollTop||void 0!==c.scrollLeft)&&t.stop(c.queue).animate(c).dequeue(c.queue)),this},o.extend(o.expr[":"],{scrollable:function(r){var l=o(r),i=!1;return o.each(e,function(r,e){return i=i||o.inArray(l.css(e.overflow).toLowerCase(),["scroll","auto"])>=0&&l.prop(e.scrollDim)>l.prop(e.clientDim),!i}),i}});var e=[{overflow:"overflow-y",scrollDim:"scrollHeight",clientDim:"clientHeight",outerDim:"outerHeight",cor:"top",scrollCor:"scrollTop"},{overflow:"overflow-x",scrollDim:"scrollWidth",clientDim:"clientWidth",outerDim:"outerWidth",cor:"left",scrollCor:"scrollLeft"}]});