index.88270f6d.js 1.3 KB

1
  1. import{d as r,Q as h,S as f,U as S,a2 as y,j as o}from"./index.394decd7.js";import{u}from"./index.75a0444f.js";const p="_sticky_1yjvp_1",g="_white_1yjvp_6",_="_animationStyle_1yjvp_13";var c={sticky:p,white:g,animationStyle:_},T=r({name:"m-sticky",props:{position:{type:String,default:"top"},mode:{type:String,default:"fixed"},offsetTop:{type:String,default:"0px"},offsetBottom:{default:"0px"},varName:{type:String,default:"--header-height"}},emits:["barHeight"],setup(t,{slots:s,emit:d}){const e=h({divStyle:{},heightV:0,sectionStyle:{width:"100%",height:"auto",left:"0"}}),l=i=>{e.sectionStyle.height=`${i}px`,e.heightV=i,document.documentElement.style.setProperty(t.varName,`${i}px`),d("barHeight",i)},m=f(),a=f();return S(()=>{t.position==="top"?e.divStyle.top=t.offsetTop||"0px":e.divStyle.bottom=t.offsetBottom||"0px";try{u(a.value,i=>{const v=i[0],{height:n}=v.contentRect;Math.abs(n-e.heightV)>1&&setTimeout(()=>{l(n)},10)})}catch{}}),y(()=>t.offsetTop,()=>{e.divStyle.top=t.offsetTop}),y(()=>t.offsetBottom,()=>{e.divStyle.bottom=t.offsetBottom}),()=>o("div",{style:[e.sectionStyle],class:t.mode==="sticky"&&c.sticky},[o("div",{ref:m,class:["van-sticky",t.mode==="fixed"?"van-sticky--fixed":"",c.animationStyle],style:[e.divStyle,e.sectionStyle]},[o("div",{ref:a,style:{position:"relative"}},[s.default&&s.default()])])])}});export{T};