国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

目錄
1、背景
2、實(shí)現(xiàn)
2.1 原理介紹
2.1 頁(yè)面布局代碼
2.2 樣式代碼
2.3 邏輯代碼
首頁(yè) 微信小程序 小程序開發(fā) 淺談小程序怎么實(shí)現(xiàn)列表滾動(dòng)上下聯(lián)動(dòng)效果

淺談小程序怎么實(shí)現(xiàn)列表滾動(dòng)上下聯(lián)動(dòng)效果

Dec 16, 2021 am 10:30 AM
小程序

小程序怎么實(shí)現(xiàn)列表滾動(dòng)上下聯(lián)動(dòng)效果?下面本篇文章給大家介紹一下微信小程序開發(fā)列表滾動(dòng)上下聯(lián)動(dòng)效果的方法,希望對(duì)大家有所幫助!

淺談小程序怎么實(shí)現(xiàn)列表滾動(dòng)上下聯(lián)動(dòng)效果

1、背景

最近在做公司的一款小程序,其中有一塊的設(shè)計(jì)的是在列表做上下滾動(dòng)的是時(shí)候,頂部的tab欄跟著一起聯(lián)動(dòng),當(dāng)點(diǎn)擊tab欄的時(shí)候,列表數(shù)據(jù)也跟隨聯(lián)動(dòng)。

下面是實(shí)現(xiàn)的一個(gè)效果圖:

淺談小程序怎么實(shí)現(xiàn)列表滾動(dòng)上下聯(lián)動(dòng)效果

頂部的頭部區(qū)域不跟隨列表滾動(dòng); 頭部區(qū)域以下屬于滾動(dòng)區(qū)域。

2、實(shí)現(xiàn)

2.1 原理介紹

這個(gè)地方的實(shí)現(xiàn)主要借助了微信小程序原生的scroll-view組件。

使用它的 scroll-into-view 屬性,可以實(shí)現(xiàn)點(diǎn)擊頂部的tab欄,將頁(yè)面滾動(dòng)到指定的列表位置;

使用 bindscroll 事件,可以知道當(dāng)前頁(yè)面滾動(dòng)的距離,根據(jù)滾動(dòng)的距離做tab欄的切換操作;

2.1 頁(yè)面布局代碼

先說下界面的整體布局,主要分為兩部分,頭部固定區(qū)域 可滾動(dòng)列表區(qū)域。

可滾動(dòng)的列表區(qū)域的標(biāo)題欄當(dāng)滾動(dòng)一定的距離后,它也要固定在頂部。

代碼實(shí)現(xiàn):

<!--index.wxml-->
<view class="list">

<!--頂部固定區(qū)域-->
<view style="height: 88rpx;width: 100%;background-color: burlywood;text-align: center;">頭部區(qū)域</view>

<!--可滾動(dòng)區(qū)域-->
<scroll-view scroll-y="true" style="width: 100%; height: {{scrollAreaHeight}}px;" bindscroll="scroll" scroll-into-view="{{scrollToItem}}" scroll-with-animation="true"  scroll-top="{{scrollTop}}">

   <!--水平滾動(dòng)的tab欄-->
  <scroll-view scroll-x="true" style="height: 88rpx;width: 100%;">
  <view class="head-area {{float ? &#39;head-float&#39; : &#39;&#39;}}" >
    <view class="head-area-item {{curSelectTab === index ? &#39;head-area-item-select&#39; : &#39;&#39;}}" wx:for="{{appGroupList}}" bindtap="tabClick" data-index="{{index}}">
    {{item.name}}
  </view>
  </view>

  </scroll-view>

<!--數(shù)據(jù)列表-->
<view class="list-group" style="height: {{listGroupHeight}}px;">
  <view class="list-group-item" id="v_{{index}}" wx:for="{{appGroupList}}" data-index="{{index}}">
    <view class="group-name">
      {{item.name}}
    </view>
    <view class="group-children" >
      <view wx:for="{{item.children}}" class="group-children-item" style="width: {{itemWidth}}px;">
      <image src="{{item.url}}"></image>
      <view>{{item.name}}</view>
    </view>
    </view>

  </view>
</view> 
</scroll-view>

</view>

在布局代碼中有幾個(gè)點(diǎn)需要注意:

1、scrollAreaHeight 滾動(dòng)區(qū)域的高度計(jì)算。 --- 通過獲取當(dāng)前設(shè)備的窗口高度減去頂部固定區(qū)域的高度

2、水平tab欄是否置頂。 --- 根據(jù)頁(yè)面的滾動(dòng)距離來判斷,如果滾動(dòng)距離 大于或者等于 水平tab欄的高度,則置頂;

3、設(shè)置數(shù)據(jù)列表的id="v_{{index}}" id,后續(xù)點(diǎn)擊tab欄滾動(dòng)到指定的位置就是根據(jù)這個(gè)id去實(shí)現(xiàn)的。

2.2 樣式代碼

/**index.wxss**/
.list{
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.head-area{
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  height: 88rpx;
  width: 100%;
  padding: 0 10;
}

.head-area-item{
  display: flex;
  height: 88rpx;
  text-align: center;
  width: 150rpx;
  align-items: center;
  justify-content: center;
}

.head-area-item-select{
  color: #09bb07;
}

image{
  width: 88rpx;
  height: 88rpx;
}

.list-group{
  display: flex;
  width: 100%;
  height: 1000%;
  flex-direction: column;
}

.list-group-item{
  display: flex;
  width: 100%;
  background-color: #aaa;
  flex-direction: column;
}

.group-name{
  height: 88rpx;
  display: flex;
  text-align: center;
  align-items: center;
  margin-left: 20rpx;
}

.group-children{
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  width: 100%;
}

.group-children-item{
  height: 160rpx;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.head-float{
  position: fixed;
  top: 88rpx;
  background-color: #ffffff;
}

2.3 邏輯代碼

// index.js
Page({
  heightArr: [],
  //記錄scroll-view滾動(dòng)過程中距離頂部的高度
  distance: 0,
  data: {
    appGroupList:[
      {name:"分組01",children:[{"name":"測(cè)試0","url":"/images/bluetooth.png"},
      {"name":"測(cè)試1","url":"/images/bluetooth.png"},
      {"name":"測(cè)試2","url":"/images/bluetooth.png"},
      {"name":"測(cè)試3","url":"/images/bluetooth.png"},
      {"name":"測(cè)試4","url":"/images/bluetooth.png"},
      {"name":"測(cè)試5","url":"/images/bluetooth.png"},
      {"name":"測(cè)試6","url":"/images/bluetooth.png"},
      {"name":"測(cè)試7","url":"/images/bluetooth.png"}]},
      {name:"分組02",children:[{"name":"測(cè)試0","url":"/images/bluetooth.png"},
      {"name":"測(cè)試1","url":"/images/bluetooth.png"},
      {"name":"測(cè)試2","url":"/images/bluetooth.png"},
      {"name":"測(cè)試3","url":"/images/bluetooth.png"},
      {"name":"測(cè)試4","url":"/images/bluetooth.png"},
      {"name":"測(cè)試5","url":"/images/bluetooth.png"},
      {"name":"測(cè)試6","url":"/images/bluetooth.png"},
      {"name":"測(cè)試7","url":"/images/bluetooth.png"}]},
      {name:"分組03",children:[{"name":"測(cè)試0","url":"/images/bluetooth.png"},
      {"name":"測(cè)試1","url":"/images/bluetooth.png"},
      {"name":"測(cè)試2","url":"/images/bluetooth.png"},
      {"name":"測(cè)試3","url":"/images/bluetooth.png"},
      {"name":"測(cè)試4","url":"/images/bluetooth.png"},
      {"name":"測(cè)試5","url":"/images/bluetooth.png"},
      {"name":"測(cè)試6","url":"/images/bluetooth.png"},
      {"name":"測(cè)試7","url":"/images/bluetooth.png"}]},
      {name:"分組04",children:[{"name":"測(cè)試0","url":"/images/bluetooth.png"},
      {"name":"測(cè)試1","url":"/images/bluetooth.png"},
      {"name":"測(cè)試2","url":"/images/bluetooth.png"},
      {"name":"測(cè)試3","url":"/images/bluetooth.png"},
      {"name":"測(cè)試4","url":"/images/bluetooth.png"},
      {"name":"測(cè)試5","url":"/images/bluetooth.png"},
      {"name":"測(cè)試6","url":"/images/bluetooth.png"},
      {"name":"測(cè)試7","url":"/images/bluetooth.png"}]},
      {name:"分組05",children:[{"name":"測(cè)試0","url":"/images/bluetooth.png"},
      {"name":"測(cè)試1","url":"/images/bluetooth.png"},
      {"name":"測(cè)試2","url":"/images/bluetooth.png"},
      {"name":"測(cè)試3","url":"/images/bluetooth.png"},
      {"name":"測(cè)試4","url":"/images/bluetooth.png"},
      {"name":"測(cè)試5","url":"/images/bluetooth.png"},
      {"name":"測(cè)試6","url":"/images/bluetooth.png"},
      {"name":"測(cè)試7","url":"/images/bluetooth.png"}]},
    ],
    itemWidth: wx.getSystemInfoSync().windowWidth / 4,
    scrollAreaHeight:wx.getSystemInfoSync().windowHeight - 44,
    float:false,
    curSelectTab:0,
    scrollToItem:null,
    scrollTop: 0, //到頂部的距離
    listGroupHeight:0,
  },

  onReady: function () {
    this.cacluItemHeight();
  },

  scroll:function(e){
    console.log("scroll:",e);
    if(e.detail.scrollTop>=44){
      this.setData({
        float : true
      })
    } else if(e.detail.scrollTop<44) {
      this.setData({
        float : false
      })
    }
    let scrollTop = e.detail.scrollTop;
    let current = this.data.curSelectTab;
    if (scrollTop >= this.distance) {
      //頁(yè)面向上滑動(dòng)
      //列表當(dāng)前可視區(qū)域最底部到頂部的距離 超過 當(dāng)前列表選中項(xiàng)距頂部的高度(且沒有下標(biāo)越界),則更新tab欄
      if (current + 1 < this.heightArr.length && scrollTop >= this.heightArr[current]) {
        this.setData({
          curSelectTab: current + 1
        })
      }
    } else { 
      //頁(yè)面向下滑動(dòng)
      //如果列表當(dāng)前可視區(qū)域最頂部到頂部的距離 小于 當(dāng)前列表選中的項(xiàng)距頂部的高度,則切換tab欄的選中項(xiàng)
      if (current - 1 >= 0 && scrollTop < this.heightArr[current - 1]) {
        this.setData({
          curSelectTab: current - 1
        })
      }
    }
    //更新到頂部的距離
    this.distance = scrollTop;
  },

  tabClick(e){
    this.setData({
      curSelectTab: e.currentTarget.dataset.index,
      scrollToItem: "v_"+e.currentTarget.dataset.index
    })
  },

  //計(jì)算每一個(gè)item高度
  cacluItemHeight() {
    let that = this;
    this.heightArr = [];
    let h = 0;
    const query = wx.createSelectorQuery();
    query.selectAll(&#39;.list-group-item&#39;).boundingClientRect()
    query.exec(function(res) {
      res[0].forEach((item) => {
        h += item.height;
        that.heightArr.push(h);
      })
      console.log(that.heightArr);
      that.setData({
        listGroupHeight: that.heightArr[that.heightArr.length - 1 ]
      })
    })
  },
})

在邏輯代碼中最主要的有兩個(gè)地方:

1、cacluItemHeight ?計(jì)算列表中item的高度數(shù)組,并將最終計(jì)算的結(jié)果保存在 heightArr數(shù)組中。

heightArr數(shù)組中的每一項(xiàng)的值是在前一項(xiàng)的基礎(chǔ)之上進(jìn)行累加。

2、scroll 中判斷當(dāng)前的滾動(dòng)方向,根據(jù)滾動(dòng)判斷當(dāng)前的方向,然后根據(jù)滾動(dòng)的距離設(shè)置當(dāng)前選擇的tab。

好了,就這么多,基于以上的內(nèi)容基本可以實(shí)現(xiàn)想要的滾動(dòng)聯(lián)動(dòng)、切換tab聯(lián)動(dòng)效果。

【相關(guān)學(xué)習(xí)推薦:小程序開發(fā)教程

以上是淺談小程序怎么實(shí)現(xiàn)列表滾動(dòng)上下聯(lián)動(dòng)效果的詳細(xì)內(nèi)容。更多信息請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請(qǐng)聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動(dòng)的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機(jī)

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強(qiáng)大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁(yè)開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)代碼編輯軟件(SublimeText3)

使用Python開發(fā)微信小程序 使用Python開發(fā)微信小程序 Jun 17, 2023 pm 06:34 PM

隨著移動(dòng)互聯(lián)網(wǎng)技術(shù)和智能手機(jī)的普及,微信成為了人們生活中不可或缺的一個(gè)應(yīng)用。而微信小程序則讓人們可以在不需要下載安裝應(yīng)用的情況下,直接使用小程序來解決一些簡(jiǎn)單的需求。本文將介紹如何使用Python來開發(fā)微信小程序。一、準(zhǔn)備工作在使用Python開發(fā)微信小程序之前,需要安裝相關(guān)的Python庫(kù)。這里推薦使用wxpy和itchat這兩個(gè)庫(kù)。wxpy是一個(gè)微信機(jī)器

實(shí)現(xiàn)微信小程序中的卡片翻轉(zhuǎn)特效 實(shí)現(xiàn)微信小程序中的卡片翻轉(zhuǎn)特效 Nov 21, 2023 am 10:55 AM

實(shí)現(xiàn)微信小程序中的卡片翻轉(zhuǎn)特效在微信小程序中,實(shí)現(xiàn)卡片翻轉(zhuǎn)特效是一種常見的動(dòng)畫效果,可以提升用戶體驗(yàn)和界面交互的吸引力。下面將具體介紹如何在微信小程序中實(shí)現(xiàn)卡片翻轉(zhuǎn)的特效,并提供相關(guān)代碼示例。首先,需要在小程序的頁(yè)面布局文件中定義兩個(gè)卡片元素,一個(gè)用于顯示正面內(nèi)容,一個(gè)用于顯示背面內(nèi)容,具體示例代碼如下:&lt;!--index.wxml--&gt;&l

支付寶上線'漢字拾光-生僻字”小程序,用于征集、補(bǔ)充生僻字庫(kù) 支付寶上線'漢字拾光-生僻字”小程序,用于征集、補(bǔ)充生僻字庫(kù) Oct 31, 2023 pm 09:25 PM

本站10月31日消息,今年5月27日,螞蟻集團(tuán)宣布啟動(dòng)“漢字拾光計(jì)劃”,最近又迎來新進(jìn)展:支付寶上線“漢字拾光-生僻字”小程序,用于向社會(huì)征集生僻字,補(bǔ)充生僻字庫(kù),同時(shí)提供不同的生僻字輸入體驗(yàn),以幫助完善支付寶內(nèi)的生僻字輸入方法。目前,用戶搜索“漢字拾光”、“生僻字”等關(guān)鍵詞就可以進(jìn)入“生僻字”小程序。在小程序里,用戶可以提交尚未被系統(tǒng)識(shí)別錄入的生僻字圖片,支付寶工程師在確認(rèn)后,將會(huì)對(duì)字庫(kù)進(jìn)行補(bǔ)錄入。本站注意到,用戶還可以在小程序體驗(yàn)最新的拆字輸入法,這一輸入法針對(duì)讀音不明確的生僻字設(shè)計(jì)。用戶拆

小程序能用react嗎 小程序能用react嗎 Dec 29, 2022 am 11:06 AM

小程序能用react,其使用方法:1、基于“react-reconciler”實(shí)現(xiàn)一個(gè)渲染器,生成一個(gè)DSL;2、創(chuàng)建一個(gè)小程序組件,去解析和渲染DSL;3、安裝npm,并執(zhí)行開發(fā)者工具中的構(gòu)建npm;4、在自己的頁(yè)面中引入包,再利用api即可完成開發(fā)。

uniapp如何實(shí)現(xiàn)小程序和H5的快速轉(zhuǎn)換 uniapp如何實(shí)現(xiàn)小程序和H5的快速轉(zhuǎn)換 Oct 20, 2023 pm 02:12 PM

uniapp如何實(shí)現(xiàn)小程序和H5的快速轉(zhuǎn)換,需要具體代碼示例近年來,隨著移動(dòng)互聯(lián)網(wǎng)的發(fā)展和智能手機(jī)的普及,小程序和H5成為了不可或缺的應(yīng)用形式。而uniapp作為一個(gè)跨平臺(tái)的開發(fā)框架,可以在一套代碼的基礎(chǔ)上,快速實(shí)現(xiàn)小程序和H5的轉(zhuǎn)換,大大提高了開發(fā)效率。本文將介紹uniapp如何實(shí)現(xiàn)小程序和H5的快速轉(zhuǎn)換,并給出具體的代碼示例。一、uniapp簡(jiǎn)介unia

教你如何在小程序中用公眾號(hào)模板消息(附詳細(xì)思路) 教你如何在小程序中用公眾號(hào)模板消息(附詳細(xì)思路) Nov 04, 2022 pm 04:53 PM

本篇文章給大家?guī)砹岁P(guān)于微信小程序的相關(guān)問題,其中主要介紹了如何在小程序中用公眾號(hào)模板消息,下面一起來看一下,希望對(duì)大家有幫助。

用Python編寫簡(jiǎn)單的聊天程序教程 用Python編寫簡(jiǎn)單的聊天程序教程 May 08, 2023 pm 06:37 PM

實(shí)現(xiàn)思路x01服務(wù)端的建立首先,在服務(wù)端,使用socket進(jìn)行消息的接受,每接受一個(gè)socket的請(qǐng)求,就開啟一個(gè)新的線程來管理消息的分發(fā)與接受,同時(shí),又存在一個(gè)handler來管理所有的線程,從而實(shí)現(xiàn)對(duì)聊天室的各種功能的處理x02客戶端的建立客戶端的建立就要比服務(wù)端簡(jiǎn)單多了,客戶端的作用只是對(duì)消息的發(fā)送以及接受,以及按照特定的規(guī)則去輸入特定的字符從而實(shí)現(xiàn)不同的功能的使用,因此,在客戶端這里,只需要去使用兩個(gè)線程,一個(gè)是專門用于接受消息,一個(gè)是專門用于發(fā)送消息的至于為什么不用一個(gè)呢,那是因?yàn)?只

PHP與小程序的地理位置定位與地圖顯示 PHP與小程序的地理位置定位與地圖顯示 Jul 04, 2023 pm 04:01 PM

PHP與小程序的地理位置定位與地圖顯示地理位置定位與地圖顯示在現(xiàn)代科技中已經(jīng)成為了必備的功能之一。隨著移動(dòng)設(shè)備的普及,人們對(duì)于定位和地圖顯示的需求也越來越高。在開發(fā)過程中,PHP和小程序是常見的兩種技術(shù)選擇。本文將為大家介紹PHP與小程序中的地理位置定位與地圖顯示的實(shí)現(xiàn)方法,并附上相應(yīng)的代碼示例。一、PHP中的地理位置定位在PHP中,我們可以使用第三方地理位

See all articles