直播软件app开发,导航条根据位置移动实现定位、颜色过渡动画效果
1.navbar、tabbar顶部导航过渡效果、颜色过渡;
<div class="mallHead">
<van-nav-bar :title="titleName" fixed @click-left="onClickLeft" :style="style" safe-area-inset-top>
<template #left>
<van-icon name="arrow-left" size="22px" color="#024EE0" />
</template>
</van-nav-bar>
<div class="top"></div>
</div>
<div :class="indexTop>220?'menuActive':'dropdown-menu'" >
<van-dropdown-menu>
<van-dropdown-item v-model="amountValue" :options="amountOption" />
<van-dropdown-item v-model="integralValue" :options="integralOption" />
<van-dropdown-item v-model="goodsValue" :options="goodsOption" />
</van-dropdown-menu>
</div>
css样式
.mallHead ::v-deep.van-nav-bar{
background: none;
.van-icon-arrow-left{
color:#fff !important;
}
.van-nav-bar__title{
color:#fff;
}
}
.mallHead ::v-deep.van-nav-bar::after{
border: 0;
}
.menuActive{
box-shadow: none;
background:#fff;
width: 100%;
position: fixed;
top: 92px;
left: 0;
z-index: 1;
}
2.定义data
data(){
return {
style:null,
indexTop:0,// 滚动条高度
amountValue:0,
amountOption:[
{ text: '兑换量从高到底', value: 0 },
{ text: '积分从低到高', value: 1 },
{ text: '积分从高到低', value: 2 },
],
.......
}
}
3.methods方法定义
mounted(){
window.addEventListener('scroll', this.handleScroll,true);
},
destroyed() {
window.removeEventListener('scroll', this.handleScroll);
},
定义handleScroll方法
Math.abs(Math.round(this.indexTop)) / 100; 自行定义
handleScroll(){
this.indexTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop; // 计算出移动位置
const opacity = Math.abs(Math.round(this.indexTop)) / 100; // 根据位置移动动态设置背景透明度
this.style = { background: `rgba(253,85,39,${opacity})`};
}
以上就是 直播软件app开发,导航条根据位置移动实现定位、颜色过渡动画效果,更多内容欢迎关注之后的文章
标签:动画,van,app,indexTop,handleScroll,导航条,Math From: https://www.cnblogs.com/yunbaomengnan/p/16915004.html