今天mui框架选项卡遇到个无法设置初始index的问题,查阅网上资料后未发现解决方案。正确的解决方案是:
1.设置头部和内容区域的.mui-active。
2.*设置内容区域最外层设置偏移量transform,根据页面宽度适配。
3:*进行silder滚动。(缺少这步会有滑动bug)
以个人需求为例:(根据地址栏设定初始值)
贴上代码:
let currIndex = getUrlParam('item')
console.log(currIndex)
//根据导航栏进行定位--MuiBug
$('.mui-control-item').removeClass('mui-active').eq(currIndex-1).addClass('mui-active')
$('.mui-slider-group>div').removeClass('mui-active').eq(currIndex-1).addClass('mui-active')
if(currIndex==1){
$(`.mui-slider-group`).css('transform','translate3d(0px, 0px, 0px) translateZ(0px)')
}else{
let screenWidth = window.innerWidth
$(`.mui-slider-group`).css('transform',`translate3d(-${screenWidth}px, 0px, 0px) translateZ(0px)`)
mui('.mui-slider').slider().gotoItem(currIndex);
}