UNPKG

disable-body-scroll

Version:

Disable the scrolling of the content of the body when the content of the pop-up window is scrolled

1 lines 1.68 kB
this.DisableBodyScroll=this.DisableBodyScroll||{},function(o){"use strict";var e=function(o){return o.scrollHeight<=o.scrollTop+o.offsetHeight},t=function(o){return 0===o.scrollTop};function n(o){o.removeEventListener("touchstart",o.$documentTouchStart),o.removeEventListener("mousemove",o.$movefunction),o.removeEventListener("mouseup",o.$upFunction)}var r=function(o,n){var r=n.value,u="disabled"===n.arg?"disabled":"working";if(void 0===document.body.style.overscrollBehavior){var i=0,s=0;o.$movefunction=function(n){n.stopPropagation();var v=c(n),a=v.offsetY-i,f=v.offsetX-s,m=a<0?"moveToTop":"moveToBottom";90==r?m=f>0?"moveToTop":"moveToBottom":-90==r&&(m=f<0?"moveToTop":"moveToBottom");var l=function(o){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"moveToTop";return!("moveToBottom"!=n||!t(o))||!("moveToTop"!=n||!e(o))}(o,m);"working"===u&&l&&n.cancelable&&n.preventDefault()},o.$upFunction=function(e){e.stopPropagation(),o.removeEventListener("mousemove",o.$movefunction),o.removeEventListener("mouseup",o.$upFunction)},o.$documentTouchStart=function(e){e.stopPropagation();var t=c(e);i=t.offsetY,s=t.offsetX,o.addEventListener("touchmove",o.$movefunction,!1),o.addEventListener("touchend",o.$upFunction,!1)},o.addEventListener("touchstart",o.$documentTouchStart,!1)}else!function(o,e){o.style.overscrollBehavior="working"==e?"contain":"auto"}(o,u);function c(o){var e={};o.targetTouches&&o.targetTouches[0]?e={offsetX:o.targetTouches[0].pageX,offsetY:o.targetTouches[0].pageY,e:o}:e={offsetX:o.offsetX,offsetY:o.offsetY,e:o};return e}};o.disabledBodyScroll=r;var u={bind:r,beforeMount:r,unbind:n,unmounted:n};o.directive=u}(this.DisableBodyScroll);