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

Home WeChat Applet WeChat Development Detailed explanation of how scroll-view completes list pages

Detailed explanation of how scroll-view completes list pages

May 14, 2018 am 09:12 AM
WeChat applet

This article mainly introduces the relevant information on the example code of the scroll-view component of the WeChat applet to implement the list page. Introduction to the scroll-view component scroll-view is a scrollable view component provided by the WeChat applet. Its main function is to use To do the pull-up loading that is often seen on mobile phones, friends who need it can refer to the introduction of

scroll-view component

scroll-view is provided by WeChat applet The scrollable view component, its main function is to do the pull-up to load and pull-down to refresh the list page that is often seen on mobile phones! Let's take "Shake out a smile" as an example to explain the component. Use !

Import a new page for the app

First we need to import a new page for our mini program and open the app in the project root directory.json This projectConfiguration fileIn the pagesarrayAdd "pages/allJoke/allJoke" and then set the bottom NavigationIn the list item of "tabBar" ("list") Add:

 {
   "text": "列表",
   "pagePath": "pages/allJoke/allJoke",
   "iconPath": "images/note.png",
   "selectedIconPath": "images/noteHL.png"
  },

If you want to know the meaning of the specific configuration, you can refer to the Mini Program Configuration document and I won’t go into details here!

json configuration page

The next step is the configuration page for our new page. Create a new directory such as alljoke under the page directory, then create a new allJoke.json under this directory, and copy the following code to this file. Inside:

{
  "navigationBarTitleText": "笑話集錦",
  "enablePullDownRefresh": true
}

Because we need to use the onPullDownRefresh method provided by the applet when doing pull-down refresh later, enablePullDownRefresh must be turned on in the configuration item. The other option is the top title of the page, which you can set at will or not. !

wxml view page

It’s the turn of the view page. Similarly, create a new alljoke.wxml page in the alljoke directory. wxml is the one created by the mini program The view page document type is written like HTML, so it is not difficult for the front-end to get started. If you need to know more about it, you can read the wxml document. Also copy the following code to alljoke.wxml

<view>
 <view>
  <scroll-view class="scroll" scroll-top="{{scrollTop}}" style="height:580px;" scroll-y="true" bindscroll="scrll"  bindscrolltolower="loadMore">
   <view class="block" wx:for="{{listLi}}" wx:for-item="item">
    <text>{{item.text}}</text>
   </view>  
  </scroll-view>
 </view>
 <view class="top" hidden="{{hidden}}" catchtap="goTop">?</view>
</view>

As you can see, we The protagonist scroll-view also makes a grand appearance here! What I brought here is a long list of configurations, let me tell you about the functions of these configurations!

##bindscrollCallback function triggered when scrolling##bindscrolltolower

用到的選項(xiàng)都列出來了,還有一點(diǎn)需要大家特別注意的:

使用豎向滾動(dòng)條時(shí)必須為組件設(shè)置一個(gè)固定高度就是上面代碼style里面設(shè)置的高!切記切記!

更多資料請(qǐng)閱讀微信小程序scroll-view組件文檔

wxss樣式

同樣在alljoke目錄下面新建allJoke.wxss文件,小程序的樣式和傳統(tǒng)css差不多大家可以根據(jù)自己喜好自行設(shè)計(jì),這里我簡(jiǎn)單做了一下樣式比較丑大家將就著用吧.(題外話:受不了的自己動(dòng)手豐衣足食)

.block {
  border: 8px solid #71b471;
  margin: 20rpx 20rpx;
  padding: 10rpx;
  background-color: #fff;
  border-radius: 20rpx;
  text-align: center;
}
.top {
  width: 100rpx;
  height: 100rpx;
  line-height: 100rpx;
  background-color: #fff;
  position: fixed;
  bottom: 40rpx;
  right: 20rpx;
  text-align: center;
  font-size: 50rpx;
  opacity: .8;
  border-radius: 50%;
  border: 1px solid #fff; 
}

小程序文檔中關(guān)于樣式的介紹

邏輯部分

來到最后也是最重要的邏輯部分了!老規(guī)矩alljoke目錄下新建allJoke.js文件,先貼代碼再慢慢講解:

Page({
 data:{
  listLi:[],
  page:1,
  scrollTop:0,
  done: false,
  hidden: true
 },
 onLoad:function(options){
  this.getList(1);
 },

 onPullDownRefresh: function(){
  wx.showToast({
   title: &#39;加載中&#39;,
   icon: &#39;loading&#39;
  });
  this.getList(1,true);
 },

 getList: function(page, stopPull){
  var that = this
  wx.request({
   url: &#39;https://wechat.sparklog.com/jokes&#39;,
   data: {
    page: page,
    per: &#39;20&#39;
   },
   method: &#39;GET&#39;, 
   success: function(res){
    if(page===1){
     that.setData({
      page: page+1,
      listLi: res.data,
      done: false
     })
     if(stopPull){
      wx.stopPullDownRefresh()      
     }
    }else{
     if(res.data<20){
      that.setData({
       page: page+1,
       listLi: that.data.listLi.concat(res.data),
       done: true
      }) 
     }else{
      that.setData({
       page: page+1,
       listLi: that.data.listLi.concat(res.data)
      }) 
     }  
    }
   },
  })
 },

 loadMore: function(){
  var done = this.data.done;
  if(done){
   return
  }else{
   wx.showToast({
    title: &#39;加載中&#39;,
    icon: &#39;loading&#39;,
    duration: 500
   });
   var page = this.data.page;
   this.getList(page)
  }
 },

 scrll: function(e){
  var scrollTop = e.detail.scrollTop
  if(scrollTop>600){
   this.setData({
    scrollTop: 1,
    hidden: false    
   })
  }else{
   this.setData({
    scrollTop: 1,
    hidden: true  
   });
  }
 },

 goTop: function(){
  this.setData({
   scrollTop:0,
   hidden: true 
  })
 }
})

大家可以看到首先我們需要用page()函數(shù)注冊(cè)頁面,然后在data里面定義一些初始化數(shù)據(jù).onLoad是這個(gè)頁面的生命周期函數(shù),頁面加載時(shí)會(huì)調(diào)用到它.我們?cè)陧撁婕虞d時(shí)調(diào)用了自定義的getList函數(shù).這個(gè)函數(shù)接收兩個(gè)參數(shù),第一個(gè)參數(shù)是要加載的頁面,第二個(gè)參數(shù)是布爾值,用來判斷是下拉刷新調(diào)用的這個(gè)函數(shù),還是頁面加載時(shí)調(diào)用的這個(gè)函數(shù)!接下來onPullDownRefresh是小程序提供的下拉刷新函數(shù),里面wx.showToast顯示消息提示框,用來提示用戶正在加載,loadMore是滾動(dòng)到底部觸發(fā)的事件.函數(shù)里面會(huì)檢查是否已經(jīng)加載了全部列表項(xiàng),如果已經(jīng)加載了全部列表項(xiàng)會(huì)return掉,如果數(shù)據(jù)庫還有列表項(xiàng),上拉到底部加載下一頁!scrll函數(shù)是滾動(dòng)時(shí)觸發(fā)的函數(shù),可以看到這個(gè)函數(shù)會(huì)判斷滾動(dòng)條位置是否大于六百,如果大于六百顯示點(diǎn)擊直達(dá)底部的按鈕,如果小于六百隱藏直達(dá)頂部的按鈕.同時(shí)會(huì)更新滾動(dòng)條位置的參數(shù).剛剛在講wxml時(shí)已經(jīng)講過scroll-view組件設(shè)置豎向滾動(dòng)條位置scroll-top設(shè)置項(xiàng)時(shí)如果參數(shù)一樣,頁面不會(huì)重新渲染,我們就是利用了這一點(diǎn),如果要到達(dá)頂部,位置必定是'0',滾動(dòng)時(shí)觸發(fā)scrll函數(shù),我們把位置信息設(shè)置為'1',因?yàn)闈L動(dòng)函數(shù)會(huì)反復(fù)觸發(fā),所以此時(shí)頁面是不會(huì)渲染的.也就是說由于位置設(shè)置參數(shù)都是設(shè)置為'1'不變,導(dǎo)致scroll-top設(shè)置項(xiàng)不會(huì)生效為goTop函數(shù)的直達(dá)頂部(把參數(shù)變?yōu)?0'提供機(jī)會(huì)).最后就是直達(dá)頂部按鈕的函數(shù)了,可以看到它是把位置信息變?yōu)?0',參數(shù)變化scroll-top設(shè)置生效,頁面直達(dá)頂部.最后再通過改變hidden這個(gè)參數(shù)把自己(直達(dá)頂部按鈕)給隱藏掉了!

結(jié)尾

ok,通過上面的步驟我們終于實(shí)現(xiàn)了下拉刷新上拉加載的列表頁功能了,從上面我們可以看到微信提供的接口api還是挺全面的,要實(shí)現(xiàn)一個(gè)功能總體來說要比原生js實(shí)現(xiàn)要簡(jiǎn)單一些!

【相關(guān)推薦】

1. 特別推薦“php程序員工具箱”V0.1版本下載

2. 微信公眾號(hào)平臺(tái)源碼下載

3. 阿貍子訂單系統(tǒng)源碼下載

The above is the detailed content of Detailed explanation of how scroll-view completes list pages. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Xianyu WeChat mini program officially launched Xianyu WeChat mini program officially launched Feb 10, 2024 pm 10:39 PM

Xianyu's official WeChat mini program has quietly been launched. In the mini program, you can post private messages to communicate with buyers/sellers, view personal information and orders, search for items, etc. If you are curious about what the Xianyu WeChat mini program is called, take a look now. What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3. If you want to use it, you must activate WeChat payment before you can purchase it;

Implement image filter effects in WeChat mini programs Implement image filter effects in WeChat mini programs Nov 21, 2023 pm 06:22 PM

Implementing picture filter effects in WeChat mini programs With the popularity of social media applications, people are increasingly fond of applying filter effects to photos to enhance the artistic effect and attractiveness of the photos. Picture filter effects can also be implemented in WeChat mini programs, providing users with more interesting and creative photo editing functions. This article will introduce how to implement image filter effects in WeChat mini programs and provide specific code examples. First, we need to use the canvas component in the WeChat applet to load and edit images. The canvas component can be used on the page

Implement the drop-down menu effect in WeChat applet Implement the drop-down menu effect in WeChat applet Nov 21, 2023 pm 03:03 PM

To implement the drop-down menu effect in WeChat Mini Programs, specific code examples are required. With the popularity of mobile Internet, WeChat Mini Programs have become an important part of Internet development, and more and more people have begun to pay attention to and use WeChat Mini Programs. The development of WeChat mini programs is simpler and faster than traditional APP development, but it also requires mastering certain development skills. In the development of WeChat mini programs, drop-down menus are a common UI component, achieving a better user experience. This article will introduce in detail how to implement the drop-down menu effect in the WeChat applet and provide practical

What is the name of Xianyu WeChat applet? What is the name of Xianyu WeChat applet? Feb 27, 2024 pm 01:11 PM

The official WeChat mini program of Xianyu has been quietly launched. It provides users with a convenient platform that allows you to easily publish and trade idle items. In the mini program, you can communicate with buyers or sellers via private messages, view personal information and orders, and search for the items you want. So what exactly is Xianyu called in the WeChat mini program? This tutorial guide will introduce it to you in detail. Users who want to know, please follow this article and continue reading! What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3.

WeChat applet implements image upload function WeChat applet implements image upload function Nov 21, 2023 am 09:08 AM

WeChat applet implements picture upload function With the development of mobile Internet, WeChat applet has become an indispensable part of people's lives. WeChat mini programs not only provide a wealth of application scenarios, but also support developer-defined functions, including image upload functions. This article will introduce how to implement the image upload function in the WeChat applet and provide specific code examples. 1. Preparatory work Before starting to write code, we need to download and install the WeChat developer tools and register as a WeChat developer. At the same time, you also need to understand WeChat

Use WeChat applet to achieve carousel switching effect Use WeChat applet to achieve carousel switching effect Nov 21, 2023 pm 05:59 PM

Use the WeChat applet to achieve the carousel switching effect. The WeChat applet is a lightweight application that is simple and efficient to develop and use. In WeChat mini programs, it is a common requirement to achieve carousel switching effects. This article will introduce how to use the WeChat applet to achieve the carousel switching effect, and give specific code examples. First, add a carousel component to the page file of the WeChat applet. For example, you can use the &lt;swiper&gt; tag to achieve the switching effect of the carousel. In this component, you can pass b

Implement image rotation effect in WeChat applet Implement image rotation effect in WeChat applet Nov 21, 2023 am 08:26 AM

To implement the picture rotation effect in WeChat Mini Program, specific code examples are required. WeChat Mini Program is a lightweight application that provides users with rich functions and a good user experience. In mini programs, developers can use various components and APIs to achieve various effects. Among them, the picture rotation effect is a common animation effect that can add interest and visual effects to the mini program. To achieve image rotation effects in WeChat mini programs, you need to use the animation API provided by the mini program. The following is a specific code example that shows how to

Implement the sliding delete function in WeChat mini program Implement the sliding delete function in WeChat mini program Nov 21, 2023 pm 06:22 PM

Implementing the sliding delete function in WeChat mini programs requires specific code examples. With the popularity of WeChat mini programs, developers often encounter problems in implementing some common functions during the development process. Among them, the sliding delete function is a common and commonly used functional requirement. This article will introduce in detail how to implement the sliding delete function in the WeChat applet and give specific code examples. 1. Requirements analysis In the WeChat mini program, the implementation of the sliding deletion function involves the following points: List display: To display a list that can be slid and deleted, each list item needs to include

See all articles
Configuration item Function
scroll-topSet the position of the vertical scroll bar. Please pay attention to if it is set The value does not change and the component will not render!
scroll-yAllow vertical scrolling
Event triggered when scrolling to the bottom
<del id="8yquy"></del>