Răsfoiți Sursa

category缩小时固定在页面顶部

zrug 5 luni în urmă
părinte
comite
985c915d5d
3 a modificat fișierele cu 6 adăugiri și 3 ștergeri
  1. 3 2
      pages/index/index.js
  2. 0 1
      pages/index/index.wxml
  3. 3 0
      pages/index/index.wxss

+ 3 - 2
pages/index/index.js

@@ -81,10 +81,10 @@ Page({
 
   onPageScroll: function(e) {
     wx.createSelectorQuery()
-      .select('.category')
+      .select('.brand-bar')
       .boundingClientRect((rect) => {
         if (rect) {
-          const shouldBeMini = rect.top <= 120; // 在高度小于120时,切换为 mini 模式
+          const shouldBeMini = rect.top <= 40; // 在brand-bar进入顶部时,category切换为mini模式
           if (this.data.isCategoryMini !== shouldBeMini) {
             this.setData({
               isCategoryMini: shouldBeMini
@@ -94,4 +94,5 @@ Page({
       })
       .exec();
   }
+  
 })

+ 0 - 1
pages/index/index.wxml

@@ -45,7 +45,6 @@
       <span>{{ item.title }}</span>
     </view>
   </view>
-  isCategoryMini {{ isCategoryMini }}
 
   <!-- 商品列表 -->
   <product-list position="index" bindaddCart="showAddCartModal"></product-list>

+ 3 - 0
pages/index/index.wxss

@@ -68,6 +68,7 @@ page {
   border-radius: 25rpx;
 }
 .category {
+  position: relative;
   height: 300rpx;
   margin: 14rpx 30rpx 10rpx 30rpx;
   border: 1px solid #097561;
@@ -84,6 +85,8 @@ page {
 
 /* mini 模式的css */
 .category.mini {
+  position: fixed; /* 固定在页面顶部 */
+  top: 0px; 
   height: 80rpx;
   padding: 0 20rpx;
   flex-wrap: nowrap;