1、引入插件

import Taro, { Component } from '@tarojs/taro'
import { View, Text, ScrollView } from '@tarojs/components'
import { AtActivityIndicator } from 'taro-ui'
import './index.scss'

2、render (){}

render () {
let dargStyle = this.state.dargStyle;
let downDragStyle = this.state.downDragStyle;
let upDragStyle = this.state.upDragStyle;
return (
<View>
<View style='width:100%;height:20vh;background:#993;' >aaaaaaaa</View>
<View className='dragUpdataPage'>
<View className='downDragBox' style={downDragStyle}>
<AtActivityIndicator></AtActivityIndicator>
<Text className='downText'>{this.state.downText}</Text>
</View>
<ScrollView
style={dargStyle}
onTouchMove={this.touchmove}
onTouchEnd={this.touchEnd}
onTouchStart={this.touchStart}
onScrollToUpper={this.ScrollToUpper}
onScrollToLower={this.ScrollToLower}
className='dragUpdata'
scrollY={this.state.scrollY}
scrollWithAnimation>
<View style='width:100%;height:60vh;background:pink;' >aaaaaaaa</View>
</ScrollView>
<View className='upDragBox' style={upDragStyle}>
<AtActivityIndicator></AtActivityIndicator>
<Text className='downText'>{this.state.pullText}</Text>
</View>
</View>
</View>
)
}

3、方法  

constructor(props) {
super(props)
this.state = {
dargStyle: {//下拉框的样式
top: 0 + 'px'
},
downDragStyle: {//下拉图标的样式
height: 0 + 'px'
},
downText: '下拉刷新',
upDragStyle: {//上拉图标样式
height: 0 + 'px'
},
pullText: '上拉加载更多',
start_p: {},
scrollY:true,
dargState: 0//刷新状态 0不做操作 1刷新 -1加载更多
}
}
reduction() {//还原初始设置
const time = 0.5;
this.setState({
upDragStyle: {//上拉图标样式
height: 0 + 'px',
transition: `all ${time}s`
},
dargState: 0,
dargStyle: {
top: 0 + 'px',
transition: `all ${time}s`
},
downDragStyle: {
height: 0 + 'px',
transition: `all ${time}s`
},
scrollY:true
})
setTimeout(() => {
this.setState({
dargStyle: {
top: 0 + 'px',
},
upDragStyle: {//上拉图标样式
height: 0 + 'px'
},
pullText: '上拉加载更多',
downText: '下拉刷新'
})
}, time * 1000);
}
touchStart(e) {
this.setState({
start_p: e.touches[0]
})
}
touchmove(e) {
let that = this
let move_p = e.touches[0],//移动时的位置
deviationX = 0.30,//左右偏移量(超过这个偏移量不执行下拉操作)
deviationY = 70,//拉动长度(低于这个值的时候不执行)
maxY = 100;//拉动的最大高度 let start_x = this.state.start_p.clientX,
start_y = this.state.start_p.clientY,
move_x = move_p.clientX,
move_y = move_p.clientY; //得到偏移数值
let dev = Math.abs(move_x - start_x) / Math.abs(move_y - start_y);
if (dev < deviationX) {//当偏移数值大于设置的偏移数值时则不执行操作
let pY = Math.abs(move_y - start_y) / 3.5;//拖动倍率(使拖动的时候有粘滞的感觉--试了很多次 这个倍率刚好)
if (move_y - start_y > 0) {//下拉操作
if (pY >= deviationY) {
this.setState({ dargState: 1, downText: '释放刷新' })
} else {
this.setState({ dargState: 0, downText: '下拉刷新' })
}
if (pY >= maxY) {
pY = maxY
}
this.setState({
dargStyle: {
top: pY + 'px',
},
downDragStyle: {
height: pY + 'px'
},
scrollY:false//拖动的时候禁用
})
}
if (start_y - move_y > 0) {//上拉操作
console.log('上拉操作')
if (pY >= deviationY) {
this.setState({ dargState: -1, pullText: '释放加载更多' })
} else {
this.setState({ dargState: 0, pullText: '上拉加载更多' })
}
if (pY >= maxY) {
pY = maxY
}
this.setState({
dargStyle: {
top: -pY + 'px',
},
upDragStyle: {
height: pY + 'px'
},
scrollY: false//拖动的时候禁用
})
} }
}
pull() {//上拉
console.log('上拉')
// this.props.onPull()
}
down() {//下拉
console.log('下拉')
// this.props.onDown()
}
ScrollToUpper() { //滚动到顶部事件
console.log('滚动到顶部事件')
// this.props.Upper()
}
ScrollToLower() { //滚动到底部事件
console.log('滚动到底部事件')
// this.props.Lower()
}
touchEnd(e) {
if (this.state.dargState === 1) {
this.down()
} else if (this.state.dargState === -1) {
this.pull()
}
this.reduction()
}

4、scss  

.dragUpdataPage{height: 50vh;position: relative;overflow: hidden;
.downDragBox{
width: 100%;
top: 0px;
display: flex;
overflow: hidden;
justify-content: center;
align-items: center;
font-size: 30px;
position: absolute;
}
.upDragBox{
bottom: 0px;
width: 100%;
display: flex;
overflow: hidden;
justify-content: center;
align-items: center;
font-size: 30px;
position: absolute;
}
.dragUpdata{height: 100%;width: 100%;position: absolute;}
.downText{margin-left: 20px;}
}

  

Taro下拉刷新,上拉加载更多的更多相关文章

  1. SwipeRefreshLayout实现下拉刷新上滑加载

    1. 效果图 2.RefreshLayout.java package myapplication.com.myapplication; import android.content.Context; ...

  2. Android 下拉刷新上啦加载SmartRefreshLayout + RecyclerView

    在弄android刷新的时候,可算是耗费了一番功夫,最后发觉有现成的控件,并且非常好用,这里记录一下. 原文是 https://blog.csdn.net/huangxin112/article/de ...

  3. juery下拉刷新,div加载更多元素并添加点击事件(二)

    buffer.append("<div class='col-xs-3 "+companyId+"' style='padding-left: 10px; padd ...

  4. 移动端下拉刷新上拉加载-mescroll.js插件

    最近无意间看到有这么一个上拉刷新下拉加载的插件 -- mescroll.js,个人感觉挺好用的,官网地址是:http://www.mescroll.com 然后我就看了一下文档,简单的写了一个小dem ...

  5. Android如何定制一个下拉刷新,上滑加载更多的容器

    前言 下拉刷新和上滑加载更多,是一种比较常用的列表数据交互方式. android提供了原生的下拉刷新容器 SwipeRefreshLayout,可惜样式不能定制. 于是打算自己实现一个专用的.但是下拉 ...

  6. Android 自定义 ListView 上下拉动“刷新最新”和“加载更多”歌曲列表

    本文内容 环境 测试数据 项目结构 演示 参考资料 本文演示,上拉刷新最新的歌曲列表,和下拉加载更多的歌曲列表.所谓"刷新最新"和"加载更多"是指日期.演示代码 ...

  7. 带你实现开发者头条APP(五)--RecyclerView下拉刷新上拉加载

    title: 带你实现开发者头条APP(五)--RecyclerView下拉刷新上拉加载 tags: -RecyclerView,下拉刷新,上拉加载更多 grammar_cjkRuby: true - ...

  8. ListView实现Item上下拖动交换位置 并且实现下拉刷新 上拉加载更多

    ListView实现Item上下拖动交换位置  并且实现下拉刷新  上拉加载更多 package com.example.ListViewDragItem; import android.app.Ac ...

  9. [ionic开源项目教程] - 第7讲 实现下拉刷新上拉加载ion-refresher和ion-infinite-scroll

    第7讲 实现下拉刷新上拉加载ion-refresher和ion-infinite-scroll 1.将tab1.html的代码改为如下: <ion-content> <ion-ref ...

  10. JS+CSS实现的下拉刷新/上拉加载插件

    闲来无事,写了一个当下比较常见的下拉刷新/上拉加载的jquery插件,代码记录在这里,有兴趣将代码写成插件与npm包可以留言. 体验地址:http://owenliang.github.io/pull ...

随机推荐

  1. C# ProgressBar的简单使用

    ProgressBar控件(进度条)用于在win窗体中显示进度,由于它的值会不断更新,为了不让界面假死,一般都是采用多线程的方式对进度条进行管理.有关ProgressBar的理论基础跟详细知识我在这里 ...

  2. PHP动态修改配置文件

    文件结构: index.php 主页 config 配置文件 doUpdate.php 修改功能页 index.php <html> <head> <title>修 ...

  3. Applied Social Network Analysis in Python 相关笔记3

    如果是option2的话,答案选A. 这里节点s,从左边的选择,节点t从右边选择. 这里计算还是用以前的值,不用更新过的值.

  4. Linux三剑客命令使用(持续更新)

    (本文档内容部分来源于网络) awk删除文件第一列 1.采用awk awk '{$1="";print $0}' file 2.采用sed sed -e 's/[^]* //' f ...

  5. 5月16日 python学习总结 DBUtils模块、orm 和 cookie、session、token

    一.DBUtils模块 介绍 The DBUtils suite is realized as a Python package containing two subsets of modules, ...

  6. WebGPU 计算管线、计算着色器(通用计算)入门案例:2D 物理模拟

    目录 1. WebGL 2. WebGPU 2.1. 适配器(Adapter)和设备(Device) 2.2. 着色器(Shaders) 2.3. 管线(Pipeline) 2.4. 并行(Paral ...

  7. 后门及持久化访问4----Com组件劫持

    代码及原理介绍 COM是Component Object Model(组件对象模型)的缩写,COM组件由DLL和EXE形式发布的可执行代码所组成.每个COM组件都有一个CLSID,这个CLSID是注册 ...

  8. phpstudy、Apache安装DVWA教程

    1.下载DVWA(http://www.dvwa.co.uk/) 2.解压缩DVWA安装包到服务器的目录下 Apache: \Apache24\htdocs phpStudy: \PHPTutoria ...

  9. 解决centos7服务器shadows已启动但是无法连接的问题

    firewall-cmd --permanent --add-port=8989/tcp firewall-cmd --reload 这是由于centos7防火墙并没有开放ss端口的问题 添加json ...

  10. Servlet的response乱码问题

    一.response有两种输出流(编码:UTF-8): 1.字节流:response.getOutputStream().write(date.getBytes("UTF-8")) ...