@tarojs/components
Version:
Taro 组件库。
1 lines • 2.85 kB
JavaScript
import{r as t,c as s,h as o,H as i,g as l}from"./p-f05e1558.js";import{c as r}from"./p-7e5d2d7a.js";import{d as c}from"./p-5746d7ce.js";function h(t,s,o){if(t===s||"number"!=typeof t)return;const i=s-t,l=Date.now(),r=s>=t;!function c(){var h;h=Date.now()-l,t=i*h/500+t,r&&t>=s||!r&&s>=t?o(s):(o(t),requestAnimationFrame(c))}()}let e=class{constructor(o){t(this,o),this.onScroll=s(this,"scroll",3),this.onScrollToUpper=s(this,"scrolltoupper",3),this.onScrollToLower=s(this,"scrolltolower",3),this.scrollX=!1,this.scrollY=!1,this.upperThreshold=50,this.lowerThreshold=50,this.scrollWithAnimation=!1,this.handleScroll=t=>{if(t instanceof CustomEvent)return;const{scrollLeft:s,scrollTop:o,scrollHeight:i,scrollWidth:l}=this.el;this._scrollLeft=s,this._scrollTop=o,this.upperAndLower(),this.onScroll.emit({scrollLeft:s,scrollTop:o,scrollHeight:i,scrollWidth:l})},this.upperAndLower=c((()=>{const{offsetWidth:t,offsetHeight:s,scrollLeft:o,scrollTop:i,scrollHeight:l,scrollWidth:r}=this.el,c=Number(this.lowerThreshold),h=Number(this.upperThreshold);!isNaN(c)&&(this.scrollY&&s+i+c>=l||this.scrollX&&t+o+c>=r)&&this.onScrollToLower.emit({direction:this.scrollX?"right":this.scrollY?"bottom":""}),!isNaN(h)&&(this.scrollY&&i<=h||this.scrollX&&o<=h)&&this.onScrollToUpper.emit({direction:this.scrollX?"left":this.scrollY?"top":""})}),200)}watchScrollLeft(t){const s=Number(t);this.scrollX&&!isNaN(s)&&s!==this._scrollLeft&&(this.scrollWithAnimation?h(this._scrollLeft,s,(t=>this.el.scrollLeft=t)):this.el.scrollLeft=s,this._scrollLeft=s)}watchScrollTop(t){const s=Number(t);this.scrollY&&!isNaN(s)&&s!==this._scrollTop&&(this.scrollWithAnimation?h(this._scrollTop,s,(t=>this.el.scrollTop=t)):this.el.scrollTop=s,this._scrollTop=s)}watchScrollIntoView(t){var s;"string"==typeof t&&t&&(null===(s=document.querySelector(`#${t}`))||void 0===s||s.scrollIntoView({behavior:"smooth",block:"center",inline:"start"}))}componentDidLoad(){const{scrollY:t,scrollX:s,scrollWithAnimation:o}=this,i=Number(this.mpScrollTop),l=Number(this.mpScrollLeft);t&&!isNaN(i)&&(o?h(0,i,(t=>this.el.scrollTop=t)):this.el.scrollTop=i,this._scrollTop=i),s&&!isNaN(l)&&(o?h(0,l,(t=>this.el.scrollLeft=t)):this.el.scrollLeft=l,this._scrollLeft=l)}render(){const{scrollX:t,scrollY:s}=this,l=r({"taro-scroll-view__scroll-x":t,"taro-scroll-view__scroll-y":s});return o(i,{class:l,onScroll:this.handleScroll},o("slot",null))}get el(){return l(this)}static get watchers(){return{mpScrollLeft:["watchScrollLeft"],mpScrollTop:["watchScrollTop"],mpScrollIntoView:["watchScrollIntoView"]}}};e.style="taro-scroll-view-core{display:block;width:100%;-webkit-overflow-scrolling:auto}taro-scroll-view-core::-webkit-scrollbar{display:none}.taro-scroll-view__scroll-x{overflow-x:scroll;overflow-y:hidden}.taro-scroll-view__scroll-y{overflow-x:hidden;overflow-y:scroll}";export{e as taro_scroll_view_core}