2 lines
1.5 KiB
JavaScript
2 lines
1.5 KiB
JavaScript
"use strict";const t=require("../../../common/vendor.js"),e={name:"fui-sticky",emits:["sticky"],options:{virtualHost:!0},props:{top:{type:[Number,String],default:0},range:{type:Boolean,default:!1},scrollTop:{type:Number,default:0},zIndex:{type:[Number,String],default:999},width:{type:[Number,String],default:750},param:{type:[Number,String],default:0}},computed:{getStyles(){let t="";return this.range||(t+=`top:${this.top}px;z-index:${this.zIndex};`),t},getStyle(){let t="";return this.range&&(t=`top:${this.top}px;z-index:${this.zIndex};`),t}},watch:{scrollTop(t){this.updateStickyChange()}},mounted(){this.$nextTick((()=>{setTimeout((()=>{this.init((()=>{this.updateStickyChange()}))}),50)}))},updated(t){this.$nextTick((()=>{this.init((()=>{this.updateStickyChange()}))}))},data:()=>({elId:`fui_${Math.ceil(1e6*Math.random()).toString(36)}`,timer:null,elTop:0,height:0,isFixed:!1}),methods:{updateStickyChange(){const t=this.elTop,e=this.height,i=this.scrollTop,s=this.top;this.range?this.isFixed=i+s>=t&&i+s<t+e:this.isFixed=i+s>=t,this.$emit("sticky",{isFixed:this.isFixed,param:this.param})},init(e){const i=`#${this.elId}`;t.index.createSelectorQuery().in(this).select(i).fields({size:!0,rect:!0},(t=>{t&&(this.elTop=t.top+(this.scrollTop||0),this.height=t.height,e&&e())})).exec()}}};const i=t._export_sfc(e,[["render",function(e,i,s,n,r,h){return{a:s.range?1:"",b:!s.range&&r.isFixed?1:"",c:t.s(h.getStyle),d:s.range?"":1,e:t.s(h.getStyles),f:r.elId}}],["__scopeId","data-v-02f29bc9"]]);wx.createComponent(i);
|