Commit 9fef7818262d2f7cc25f21d56a9fc55cca60e83d

Authored by zhiyangdu
1 parent c7613651

首页头部固定

src/pages/pointsMall/pointsMall.less
... ... @@ -10,6 +10,11 @@
10 10 height: 93px;
11 11 }
12 12 }
  13 +// 列表
  14 +.column-list-box{
  15 + display: flex;
  16 + justify-content: center;
  17 +}
13 18 .hide{
14 19 display:none;
15 20 }
... ... @@ -19,6 +24,10 @@
19 24 }
20 25 .back-box{
21 26 background-color: transparent;
  27 + position: fixed;
  28 + top: 0;
  29 + left:0;
  30 + z-index: 2;
22 31 }
23 32 .main_box{
24 33 width: 100%;
... ...
src/pages/pointsMall/pointsMall.vue
... ... @@ -12,11 +12,13 @@
12 12 <!-- pl -->
13 13 <div class="pl" :class="{'is-open-app': $parent.isOpenApp.value, 'hide': $route.query.hideBack == true}"></div>
14 14 <div class="main_box">
  15 + <!-- pl -->
  16 + <div class="pl" :class="{'is-cnlive': isCNLive.value, 'hide': $route.query.hideBack == true}"></div>
15 17 <back-box
16 18 v-if="isCNLive.value"
17 19 :class="{'hide': $route.query.hideBack == true}"
18 20 class="back-box"
19   - :style="'padding-top: ' + $parent.top.value + 'px'"
  21 + :style="'padding-top: ' + $parent.top.value + 'px; background-color: rgba(255, 248, 232, ' + opacity + ')'" ref="navBox"
20 22 @back="back"
21 23 :backs="backs">
22 24 </back-box>
... ... @@ -123,6 +125,7 @@ export default {
123 125 name: 'pointsmall',
124 126 data () {
125 127 return {
  128 + opacity: 0, // 透明度
126 129 title: "", // 标题
127 130 backs: null, // 后退按钮组
128 131 navs: null, // 导航
... ... @@ -313,6 +316,47 @@ export default {
313 316 Toast(res.message);
314 317 }
315 318 },
  319 +
  320 + /**
  321 +* 滚动条滚动/touchmove监听处理
  322 +* @param {object} e [滚动条对象]
  323 +* @param {boolean} isTimeout [是否为setTimeout方法调用]
  324 +*/
  325 + onPageScrollFun (e, isTimeout = false) {
  326 +
  327 + // 获取滚动条位置,浏览器兼容处理
  328 + let scrollTop = (document.documentElement.scrollTop || document.body.scrollTop) || 0;
  329 +
  330 + // 滚动控制高度
  331 + let maxHeight = 200;
  332 +
  333 + // 动态获取百分比分配比例
  334 + if (typeof this.$refs === "object" && typeof this.$refs.navBox === "object" && typeof this.$refs.navBox.clientHeight === "number") {
  335 + maxHeight = (this.$refs.navBox.clientHeight + this.$parent.top.value) * 2;
  336 + }
  337 +
  338 + if (scrollTop >= 0 && scrollTop <= maxHeight) {
  339 + this.opacity = scrollTop / maxHeight;
  340 + } else if (scrollTop > maxHeight) {
  341 + this.opacity = 1;
  342 + } else {
  343 + this.opacity = 0;
  344 + }
  345 +
  346 + if (!isTimeout) {
  347 +
  348 + if (this.timer) {
  349 + clearTimeout(this.timer);
  350 + }
  351 +
  352 + // 倒计时校正滚动条位置
  353 + this.timer = setTimeout(function (options) {
  354 +
  355 + // 递归
  356 + options.context.onPageScrollFun(options.e, true);
  357 + }, 1000, { e, context: this });
  358 + }
  359 + }
316 360 },
317 361 head: {
318 362 title () {
... ... @@ -391,6 +435,8 @@ export default {
391 435 });
392 436 }
393 437 }
  438 + // 监听滚动条,设置滚动条推动渐变颜色和图片
  439 + window.addEventListener("scroll", this.onPageScrollFun, true);
394 440 }
395 441 }
396 442 </script>
... ...