parent
658f1dbde9
commit
6d3dc36783
@ -0,0 +1,62 @@
|
||||
// components/navBar.js
|
||||
const app = getApp();
|
||||
Component({
|
||||
/**
|
||||
* 组件的属性列表
|
||||
*/
|
||||
options: {
|
||||
multipleSlots: true//开启多个插槽
|
||||
},
|
||||
properties: { //传参属性
|
||||
navBarStyle:{
|
||||
type:Number,
|
||||
value:0
|
||||
},
|
||||
scrollCss:{
|
||||
type:Number,
|
||||
value:0
|
||||
},
|
||||
textColor:{
|
||||
type:String,
|
||||
value:''
|
||||
},
|
||||
titlebg:{
|
||||
type:String,
|
||||
value:''
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* 组件的初始数据
|
||||
*/
|
||||
data: {
|
||||
navBarHeight: app.globalData.navBarHeight, //导航栏高度
|
||||
menuRight: app.globalData.menuRight, // 胶囊距右方间距(方保持左、右间距一致)
|
||||
menuBotton: app.globalData.menuBotton,
|
||||
menuHeight: app.globalData.menuHeight,
|
||||
menuWidth: app.globalData.menuWidth
|
||||
},
|
||||
/**
|
||||
* 组件的方法列表
|
||||
*/
|
||||
methods: {
|
||||
|
||||
},
|
||||
onPageScroll: function (e) {
|
||||
console.log("页面滚动距离:",e);
|
||||
if(e.scrollTop > 80 && e.scrollTop < 100){
|
||||
this.setData({
|
||||
navBarStyle:1
|
||||
})
|
||||
}
|
||||
else if(e.scrollTop > 100){
|
||||
this.setData({
|
||||
navBarStyle:2
|
||||
})
|
||||
}else{
|
||||
this.setData({
|
||||
navBarStyle:0
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<view class="nav {{scrollCss>10? 'navstyl' : 'unnavstyl'}}" style="height:{{navBarHeight}}px;background: {{titlebg}};">
|
||||
<view class="nav-main" style="height:{{menuHeight}}px;bottom:{{menuBotton}}px;left:{{menuRight}}px;right:{{menuRight}}px">
|
||||
<!-- 胶囊区域 -->
|
||||
<view class="capsule-box" style="height:{{menuHeight}}px;width:{{menuWidth}}px"></view>
|
||||
<!-- 导航内容区域 -->
|
||||
<view class="left" style="color:{{textColor}}">
|
||||
<slot name="left"></slot>
|
||||
</view>
|
||||
<view class="mid" style="color:{{textColor}}">
|
||||
<slot name="mid"></slot>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- class="nav {{ navBarStyle == 2 ? 'activeNavBar' : ''}} {{ navBarStyle == 1 ? 'gradual' : ''}}" -->
|
@ -0,0 +1,51 @@
|
||||
.nav {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 999;
|
||||
width: 100vw;
|
||||
}
|
||||
/* 半透明渐变过渡 */
|
||||
.nav.gradual {
|
||||
background: -webkit-linear-gradient(top, transparent, rgba(255, 255, 255, 0.4) 30%);
|
||||
background: -moz-linear-gradient(top, transparent, rgba(255, 255, 255, 0.4) 30%);
|
||||
background: -o-linear-gradient(top, transparent, rgba(255, 255, 255, 0.4) 30%);
|
||||
background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.4) 30%);
|
||||
}
|
||||
.nav.activeNavBar {
|
||||
background: #ffffff;
|
||||
}
|
||||
.nav-main {
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.nav-main .mid {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
font-size: 35rpx;
|
||||
font-family: "Alibaba-PuHuiTi-Bold.otf";
|
||||
font-weight: bold;
|
||||
color: #000000;
|
||||
}
|
||||
.nav-main .left{
|
||||
font-size: 35rpx;
|
||||
color: #000000;
|
||||
margin-left: 20rpx;
|
||||
}
|
||||
/* 胶囊 */
|
||||
.nav-main .capsule-box {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.navstyl{
|
||||
background: #ffffff;
|
||||
transition: all 1.5s;
|
||||
}
|
||||
.unnavstyl{
|
||||
transition: all 1.5s;
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"usingComponents": {
|
||||
"my-navBar":"/navBar/index"
|
||||
},
|
||||
"navigationStyle":"custom"
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"usingComponents": {
|
||||
"my-navBar":"/navBar/index"
|
||||
},
|
||||
"navigationStyle":"custom"
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"usingComponents": {
|
||||
"my-navBar":"/navBar/index"
|
||||
},
|
||||
"navigationStyle":"custom"
|
||||
|
||||
}
|
Loading…
Reference in new issue