1 |
- import{d as u,x as g,r as d,y as S,w as y,a}from"./index-b2591f11.js";import{d as h}from"./index-9105746d.js";const x="_sticky_4d2w6_1",p="_white_4d2w6_6",k={sticky:x,white:p},b=u({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(e,{slots:c,emit:l,expose:m}){const t=g({divStyle:{},heightV:0,sectionStyle:{width:"100%",height:"auto",left:"0"}}),f=o=>{t.sectionStyle.height=`${o}px`,t.heightV=o,document.documentElement.style.setProperty(e.varName,`${o}px`),l("barHeight",o)},r=d(),s=d();S(()=>{e.position==="top"?t.divStyle.top=e.offsetTop||"0px":t.divStyle.bottom=e.offsetBottom||"0px";try{h(s.value,o=>{const n=o[0],{height:i}=n.contentRect;Math.abs(i-t.heightV)>1&&setTimeout(()=>{f(i)},10)})}catch(o){}});const v=()=>{try{h(s.value,o=>{const n=o[0],{height:i}=n.contentRect;Math.abs(i-t.heightV)>1&&setTimeout(()=>{f(i)},10)})}catch(o){}};return y(()=>e.offsetTop,()=>{t.divStyle.top=e.offsetTop}),y(()=>e.offsetBottom,()=>{t.divStyle.bottom=e.offsetBottom}),m({onChnageHeight:v}),()=>a("div",{style:[t.sectionStyle],class:e.mode==="sticky"&&k.sticky},[a("div",{ref:r,class:["van-sticky",e.mode==="fixed"?"van-sticky--fixed":""],style:[t.divStyle,t.sectionStyle]},[a("div",{ref:s},[c.default&&c.default()])])])}});export{b as M};
|