Home > Web Front-end > JS Tutorial > body text

Detailed explanation of mescroll.js pull-up loading pull-down refresh component

小云云
Release: 2018-01-19 13:25:27
Original
3042 people have browsed it

This article mainly introduces the use of the mescroll.js pull-up, load, and pull-down refresh components in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

Precautions for use:

1. If there is a problem when introducing it, please check the official solution in time (basically you must read it);

2. In react, it must be initialized in the method (didMount) after dom rendering, because this requires getting the dom object;

3. In the react project, callback The data must be spliced, which should be noted (datas:ctx.state.datas.concat(json.info));

4. It is very tricky to need the html and body in a single page. The height is set to 100%.

A simple code is attached below


##

import React, { Component, PropTypes } from 'react'; 
import MeScroll from "mescroll.js" 
 
class StretchingUp extends Component { 
  constructor(props, context) { 
    super(props, context); 
    this.state={ 
      datas:[], 
      total:0, 
    } 
    this.test = this.test.bind(this); 
  } 
  componentDidMount(){ 
    document.ondragstart=function() {return false;} 
    let ctx = this; 
    var mescroll = new MeScroll ( "mescroll" , {down : { use:false}, up : { 
      use:true, 
      auto:true, 
      offSet:100, 
      page:{ 
        num:0, 
        size:20, 
        time:null 
      }, 
      onScroll:function(mescroll, y, isUp){ 
      }, 
      callback:function (page, mescroll) { 
        ctx.test(page, mescroll); 
      }, 
      error: function (e) { 
      } 
    }} ) ; 
    mescroll.resetUpScroll() 
  } 
  test(page, mescroll){ 
    console.log(page) 
    let url = "http://localhost:5577/curpage/"+page.num+"/pagesize/"+page.size; 
    let ctx = this; 
    fetch(url,{ 
      method:'GET', 
      headers: { 
        'Accept': 'application/json', 
        'Content-Type': 'application/json', 
      }, 
    }).then((resp)=>{ 
      if(resp){ 
        return resp.json(); 
      }else{ 
        return false; 
      } 
    }) 
    .then((json)=>{ 
        ctx.setState({ 
        datas:ctx.state.datas.concat(json.info), 
        total:json.total 
      },()=>{ 
    }) 
 
    mescroll.endSuccess(); 
    return true; 
  }); 
  } 
  render() { 
    return ( 
      <p id="mescroll" className="mescroll" style={{height: "500px",overflow: "auto"}}> 
      {this.state.datas.map((item,index)=>( 
        <p key={index}> 
          {item.id} 
        </p> 
      ))} 
      </p> 
  ); 
  }} 
 
export default StretchingUp;
Copy after login

Related recommendations:


WeChat Mini Program development list pull-up loading pull-down refresh sample code

##dropload.js plug-in pull-down refresh and pull-up loading method

Example detailed explanation of mui pull-up Encapsulation process of loading more drop-down refresh data

The above is the detailed content of Detailed explanation of mescroll.js pull-up loading pull-down refresh component. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!