weweb-cli
Version:
微信小程序转成h5的小工具
1 lines • 5.85 kB
JavaScript
webpackJsonp([7],{297:function(o,t,l){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=window.exparser.registerElement({is:"wx-scroll-view",template:'\n <div id="main" class="wx-scroll-view" style$="overflow-x: hidden; overflow-y: hidden;">\n <slot></slot>\n </div>\n ',behaviors:["wx-base","wx-touchtrack"],properties:{scrollX:{type:Boolean,value:!1,public:!0,observer:"_scrollXChanged"},scrollY:{type:Boolean,value:!1,public:!0,observer:"_scrollYChanged"},upperThreshold:{type:Number,value:50,public:!0},lowerThreshold:{type:Number,value:50,public:!0},scrollTop:{type:Number,coerce:"_scrollTopChanged",public:!0},scrollLeft:{type:Number,coerce:"_scrollLeftChanged",public:!0},scrollIntoView:{type:String,coerce:"_srollIntoViewChanged",public:!0}},created:function(){this._lastScrollTop=this.scrollTop||0,this._lastScrollLeft=this.scrollLeft||0,this.touchtrack(this.$.main,"_handleTrack")},attached:function(){var o=this;if(this._scrollTopChanged(this.scrollTop),this._scrollLeftChanged(this.scrollLeft),this._srollIntoViewChanged(this.scrollIntoView),this.__handleScroll=function(t){t.preventDefault(),t.stopPropagation(),o._handleScroll.bind(o,t)()},this.__handleTouchMove=function(t){o._checkBounce();var l=t.touches[0].pageY,e=o.$.main;o.__touchStartY<l?e.scrollTop>0&&t.stopPropagation():e.scrollHeight>e.offsetHeight+e.scrollTop&&t.stopPropagation()},this.__handleTouchStart=function(t){o.__touchStartY=t.touches[0].pageY,WeixinJSBridge.invoke("disableScrollBounce",{disable:!0},function(){});var l=o.$.main;o._touchScrollTop=o.$.main.scrollTop,o._touchScrollLeft=o.$.main.scrollLeft,o._touchScrollBottom=o._touchScrollTop+l.offsetHeight===l.scrollHeight,o._touchScrollRight=o._touchScrollLeft+l.offsetWidth===l.scrollWidth},this.__handleTouchEnd=function(){WeixinJSBridge.invoke("disableScrollBounce",{disable:!1},function(){})},this.$.main.addEventListener("touchstart",this.__handleTouchStart),this.$.main.addEventListener("touchmove",this.__handleTouchMove),this.$.main.addEventListener("touchend",this.__handleTouchEnd),this.$.main.addEventListener("scroll",this.__handleScroll),this.$.main.style.overflowX=this.scrollX?"auto":"hidden",this.$.main.style.overflowY=this.scrollY?"auto":"hidden",/iphone/.test(window.navigator.userAgent.toLowerCase())){document.getElementById("__scroll_view_hack")&&document.body.removeChild(document.getElementById("__scroll_view_hack"));var t=document.createElement("div");t.setAttribute("style","position: fixed; left: 0; bottom: 0; line-height: 1; font-size: 1px; z-index: 10000; border-radius: 4px; box-shadow: 0 0 8px rgba(0,0,0,.4); width: 1px; height: 1px; overflow: hidden;"),t.innerText=".",t.id="__scroll_view_hack",document.body.appendChild(t)}},detached:function(){this.$.main.removeEventListener("scroll",this.__handleScroll),this.$.main.removeEventListener("touchstart",this.__handleTouchStart),this.$.main.removeEventListener("touchmove",this.__handleTouchMove),this.$.main.removeEventListener("touchend",this.__handleTouchEnd)},_getStyle:function(o,t){return"overflow-x: "+(o?"auto":"hidden")+"; overflow-y: "+(t?"auto":"hidden")+";"},_handleTrack:function(o){return"start"===o.detail.state?(this._x=o.detail.x,this._y=o.detail.y,void(this._noBubble=null)):("end"===o.detail.state&&(this._noBubble=!1),null===this._noBubble&&this.scrollY&&(Math.abs(this._y-o.detail.y)/Math.abs(this._x-o.detail.x)>1?this._noBubble=!0:this._noBubble=!1),null===this._noBubble&&this.scrollX&&(Math.abs(this._x-o.detail.x)/Math.abs(this._y-o.detail.y)>1?this._noBubble=!0:this._noBubble=!1),this._x=o.detail.x,this._y=o.detail.y,void(this._noBubble&&o.stopPropagation()))},_handleScroll:function(o){this._bounce||(clearTimeout(this._timeout),this._timeout=setTimeout(function(){var o=this.$.main;if(this.triggerEvent("scroll",{scrollLeft:o.scrollLeft,scrollTop:o.scrollTop,scrollHeight:o.scrollHeight,scrollWidth:o.scrollWidth,deltaX:this._lastScrollLeft-o.scrollLeft,deltaY:this._lastScrollTop-o.scrollTop}),this.scrollY){var t=this._lastScrollTop-o.scrollTop>0,l=this._lastScrollTop-o.scrollTop<0;o.scrollTop<=this.upperThreshold&&t&&this.triggerEvent("scrolltoupper",{direction:"top"}),o.scrollTop+o.offsetHeight+this.lowerThreshold>=o.scrollHeight&&l&&this.triggerEvent("scrolltolower",{direction:"bottom"})}if(this.scrollX){var e=this._lastScrollLeft-o.scrollLeft>0,i=this._lastScrollLeft-o.scrollLeft<0;o.scrollLeft<=this.upperThreshold&&e&&this.triggerEvent("scrolltoupper",{direction:"left"}),o.scrollLeft+o.offset__wxConfigWidth+this.lowerThreshold>=o.scrollWidth&&i&&this.triggerEvent("scrolltolower",{direction:"right"})}this.scrollTop=this._lastScrollTop=o.scrollTop,this.scrollLeft=this._lastScrollLeft=o.scrollLeft}.bind(this),50))},_checkBounce:function(){var o=this,t=o.$.main;0===o._touchScrollTop&&(!o._bounce&&t.scrollTop<0&&(o._bounce=!0),o._bounce&&t.scrollTop>0&&(o._bounce=!1)),0===o._touchScrollLeft&&(!o._bounce&&t.scrollLeft<0&&(o._bounce=!0),o._bounce&&t.scrollLeft>0&&(o._bounce=!1)),o._touchScrollBottom&&(!o._bounce&&t.scrollTop>o._touchScrollTop&&(o._bounce=!0),o._bounce&&t.scrollTop<o._touchScrollTop&&(o._bounce=!1)),o._touchScrollRight&&(!o._bounce&&t.scrollLeft>o._touchScrollLeft&&(o._bounce=!0),o._bounce&&t.scrollLeft<o._touchScrollLeft&&(o._bounce=!1))},_scrollXChanged:function(o){this.$.main.style.overflowX=o?"auto":"hidden"},_scrollYChanged:function(o){this.$.main.style.overflowY=o?"auto":"hidden"},_scrollTopChanged:function(o){this.scrollY&&(this.$.main.scrollTop=o)},_scrollLeftChanged:function(o){this.scrollX&&(this.$.main.scrollLeft=o)},_srollIntoViewChanged:function(o){if(o){if(Number(o[0])>=0&&Number(o[0])<=9)return console.group('scroll-into-view="'+o+'" 有误'),console.warn("id属性不能以数字开头"),void console.groupEnd();var t=this.$$.querySelector("#"+o);t&&(this.$.main.scrollTop=t.offsetTop)}}})}});