u-sticky._cSIV75r.js 2.13 KB
import{aw as t,b6 as e,o as s,d as i,w as n,e as o,H as h,L as r,_ as d,i as a}from"./index-GKdQHgvR.js";import{_ as c}from"./_plugin-vue_export-helper.BCo6x5W8.js";const l=c({name:"u-sticky",emits:["fixed","unfixed"],props:{offsetTop:{type:[Number,String],default:0},index:{type:[Number,String],default:""},enable:{type:Boolean,default:!0},h5NavHeight:{type:[Number,String],default:44},bgColor:{type:String,default:"#ffffff"},zIndex:{type:[Number,String],default:""}},data(){return{fixed:!1,height:"auto",stickyTop:0,elClass:this.$u.guid(),left:0,width:"auto"}},watch:{offsetTop(t){this.initObserver()},enable(t){0==t?(this.fixed=!1,this.disconnectObserver("contentObserver")):this.initObserver()}},computed:{uZIndex(){return this.zIndex?this.zIndex:this.$u.zIndex.sticky}},mounted(){this.initObserver()},methods:{initObserver(){this.enable&&(this.stickyTop=0!=this.offsetTop?t(this.offsetTop)+this.h5NavHeight:this.h5NavHeight,this.disconnectObserver("contentObserver"),this.$uGetRect("."+this.elClass).then((t=>{this.height=t.height,this.left=t.left,this.width=t.width,this.$nextTick((()=>{this.observeContent()}))})))},observeContent(){this.disconnectObserver("contentObserver");const t=e(this,{thresholds:[.95,.98,1]});t.relativeToViewport({top:-this.stickyTop}),t.observe("."+this.elClass,(t=>{this.enable&&this.setFixed(t.boundingClientRect.top)})),this.contentObserver=t},setFixed(t){const e=t<this.stickyTop;e?this.$emit("fixed",this.index):this.fixed&&this.$emit("unfixed",this.index),this.fixed=e},disconnectObserver(t){const e=this[t];e&&e.disconnect()}},beforeUnmount(){this.disconnectObserver("contentObserver")}},[["render",function(t,e,c,l,f,u){const p=a;return s(),i(p,{class:""},{default:n((()=>[o(p,{class:h(["u-sticky-wrap",[f.elClass]]),style:r({height:f.fixed?f.height+"px":"auto",backgroundColor:c.bgColor})},{default:n((()=>[o(p,{class:"u-sticky",style:r({position:f.fixed?"fixed":"static",top:f.stickyTop+"px",left:f.left+"px",width:"auto"==f.width?"auto":f.width+"px",zIndex:u.uZIndex})},{default:n((()=>[d(t.$slots,"default",{},void 0,!0)])),_:3},8,["style"])])),_:3},8,["class","style"])])),_:3})}],["__scopeId","data-v-ecb5b5db"]]);export{l as _};