Commit 1f50d33a by 侯体倬

首页沉侵式优化

parent 13680ef1
...@@ -85,6 +85,7 @@ export default { ...@@ -85,6 +85,7 @@ export default {
height: 100%; height: 100%;
background: linear-gradient(rgba(0, 0, 0, 0) 10%, rgb(255, 255, 255) 40%); background: linear-gradient(rgba(0, 0, 0, 0) 10%, rgb(255, 255, 255) 40%);
} }
transition: background-color .5s;
} }
.ThemeDataPlant::before { .ThemeDataPlant::before {
......
<template> <template>
<div class="CustomNav"> <div class="CustomNav" :style="zIndexStyle">
<div class="navFixedBg" :style="{ 'height': navHeight + 'px' }"> <div class="navFixedBg" :style="navFixedBgStyle"></div>
</div> <div class="navBg" :style="navBgStyle">
<div class="navBg" <div class="content" :style="contentStyle">{{showShopName}}</div>
:style="{ 'height': navHeight + 'px', background: 'rgba(255,255,255,' + (customBgOpacity ? bgOpacity : 1) + ')' }">
<div class="content" :style="{ 'top': navTop + 'px', height: navConHeight + 'px' }">
{{ title || shopName }}
</div>
</div> </div>
</div> </div>
</template> </template>
<script type="text/ecmascript-6"> <script type="text/ecmascript-6">
const app = getApp(); let navHeight, navTop, navConHeight;
const { log } = app;
export default { export default {
name: "CustomNav", name: "CustomNav",
props: { props: {
...@@ -28,64 +23,78 @@ export default { ...@@ -28,64 +23,78 @@ export default {
}, },
data() { data() {
return { return {
navHeight: 0, shopName: ' ',
navTop: 0,
navConHeight: 0,
bgOpacity: 0, bgOpacity: 0,
zIndexStyle: '',
navFixedBgStyle: '',
navBgStyle: '',
contentStyle: ''
} }
}, },
components: {}, created() {
computed: { this.getNavbarInfo();
shopName() { this.initialize();
// let shopName = app.globalData && app.globalData.shopInfo && app.globalData.shopInfo.shopName;
let shopName = wx.getStorageSync("shopName");
return shopName || "";
}, },
listHeight() { onPageScroll(el) {
return `calc(100vh - ${this.navConHeight}px - ${this.navTop}px - 0.5rem )` this.getScroll(el);
}, },
topBgHeight() { watch: {
return `calc(2rem + ${this.navTop}px)` customBgOpacity() {
wx.nextTick(() => {
this.initialize();
this.$forceUpdate();
})
}
}, },
topHeight() { computed: {
return `calc(2rem + ${this.navTop}px)` showShopName() {
return this.shopName;
} }
}, },
created() { }, methods: {
onLoad() { initialize() {
this.getNavbarInfo(); this.setShopName();
this.setZIndexStyle();
this.setNavFixedBgStyle();
this.setNavBgStyle();
this.setContentStyle();
}, },
onShow() { getScroll(el) {
let opacity = (el.scrollTop / 100).toFixed(1) - 0;
this.bgOpacity = opacity > 1 ? 1 : opacity;
this.setNavBgStyle();
this.setContentStyle();
}, },
onReady() { getNavbarInfo() {
const { height, top } = wx.getMenuButtonBoundingClientRect();
const { statusBarHeight } = wx.getSystemInfoSync()
navTop = statusBarHeight;
navHeight = (statusBarHeight + height + (top - statusBarHeight) * 2);
navConHeight = (height + (top - statusBarHeight) * 2);
}, },
onHide() { setShopName() {
this.shopName = this.title || wx.getStorageSync("shopName");
}, },
onUnload() { setZIndexStyle() {
this.zIndexStyle = `z-index: ${this.customBgOpacity ? 9991 : 9999};`;
}, },
onPageScroll(el) { setNavFixedBgStyle() {
this.getScroll(el); this.navFixedBgStyle = `height:${this.customBgOpacity ? navTop : navHeight}px;`;
}, },
mounted() { }, setNavBgStyle() {
methods: { this.navBgStyle = `
getScroll(el) { height: ${navHeight}px;
let opacity = (el.scrollTop / 100).toFixed(1) - 0; background:rgba(255, 255, 255, ${this.customBgOpacity ? this.bgOpacity : 1});
this.bgOpacity = opacity > 1 ? 1 : opacity; `;
},
setContentStyle() {
this.contentStyle = `
top: ${navTop}px;
height: ${navConHeight}px;
opacity: ${this.customBgOpacity ? this.bgOpacity : 1};
`;
}, },
getNavbarInfo() {
let menuInfo = wx.getMenuButtonBoundingClientRect();
console.log(menuInfo, '-menuInfo')
let res = wx.getSystemInfoSync()
console.log(res, '-getSystemInfoSync')
this.navTop = res.statusBarHeight;
this.navHeight = (res.statusBarHeight + menuInfo.height + (menuInfo.top - res.statusBarHeight) * 2)
this.navConHeight = (menuInfo.height + (menuInfo.top - res.statusBarHeight) * 2);
console.log(this.navTop, this.navHeight, this.navConHeight, '-this.navConHeight')
}
} }
} }
</script> </script>
...@@ -93,7 +102,6 @@ export default { ...@@ -93,7 +102,6 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
.CustomNav { .CustomNav {
position: relative; position: relative;
z-index: 9999;
.navFixedBg { .navFixedBg {
width: 100%; width: 100%;
......
...@@ -116,6 +116,8 @@ export default { ...@@ -116,6 +116,8 @@ export default {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.storeAddr { .storeAddr {
position: relative;
z-index: 9992;
padding: 6px 12px; padding: 6px 12px;
justify-content: space-between; justify-content: space-between;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment