UNPKG

1.92 kBJavaScriptView Raw
1!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.MugenScroll=n()}(this,function(){"use strict";function e(e,n){function t(){l=0,s=+new Date,i=e.apply(o,r),o=null,r=null}var o,r,i,l,s=0;return function(){o=this,r=arguments;var e=new Date-s;return l||(e>=n?t():l=setTimeout(t,n-e)),i}}var n=e,t=function(e,n){void 0===n&&(n={});var t=n.offset;void 0===t&&(t=0);var o=n.threshold;void 0===o&&(o=0);var r=e.getBoundingClientRect(),i=r.top,l=r.right,s=r.bottom,c=r.left,a=r.width,u=r.height,h={t:s,r:window.innerWidth-c,b:window.innerHeight-i,l:l},d={x:o*a,y:o*u};return h.t>=(t.top||t+d.y)&&h.r>=(t.right||t+d.x)&&h.b>=(t.bottom||t+d.y)&&h.l>=(t.left||t+d.x)},o=t,r=["scroll","resize"],i={name:"mugen-scroll",props:{handler:{type:Function,required:!0},shouldHandle:{type:Boolean,default:!0},threshold:{type:Number,default:0},handleOnMount:{type:Boolean,default:!0},scrollContainer:{type:String}},mounted:function(){this.checkInView()},methods:{checkInView:function(){var e=this,t=function(){if(e.$refs.scroll){var n=o(e.$refs.scroll,{threshold:e.threshold});e.shouldHandle&&n&&e.handler()}};if(this.handleOnMount&&t(),this.scrollContainer){for(var i=this;(i=i.$parent)&&!this._scrollContainer;)e._scrollContainer=i.$refs[e.scrollContainer];this._scrollContainer&&this._scrollContainer.$el&&(this._scrollContainer=this._scrollContainer.$el)}this._scrollContainer=this._scrollContainer||window,this.check=n(t,200),r.forEach(function(n){return e._scrollContainer.addEventListener(n,e.check)})}},render:function(e){return e("div",{staticClass:"mugen-scroll",ref:"scroll"},this.$slots.default)},beforeDestroy:function(){var e=this;r.forEach(function(n){return e._scrollContainer.removeEventListener(n,e.check)})}};return"undefined"!=typeof window&&window.Vue&&window.Vue.component(i.name,i),i});
2//# sourceMappingURL=vue-mugen-scroll.min.js.map