Giter VIP home page Giter VIP logo

tractor.js's Introduction

tractor.js

移动端下拉加载(刷新)和滚动加载,无依赖,支持现代浏览器。

Example

Demo

Usage

npm install --save tractor.js

// ES6
import Tractor from 'tractor'
new Tractor(options)

// or

<script src="node_modules/tractor/dist/tractor.js"></script>
<script>
  new Tractor(options)
</script>

Options

  • scroller{String} @require

    容器:使用 document.querySelector(scroller) 获取 HTMLElement

  • enableDragLoading{Boolean} @default = false

    启用下拉加载(刷新)功能

  • enableScrollLoading - {Boolean} @default = false

    启用滚动加载功能

  • avoidHorizontalSliding{Boolean} @default = false

    避免横向滑屏:防止误操作,比如手指横向滑动的同时也有一些距离的竖向滑动(下拉)

  • dragThreshold{Number} @default = 40

    下拉加载(刷新)阈值:手指离开屏幕时触发下拉加载(刷新)行为的临界值

  • scrollThreshold{Number} @default = 40

    滚动加载阈值:容器滚动到底部时触发滚动加载行为的临界值

  • onDragStart{Function} @default = null

    下拉开始 hook:手指触碰屏幕时触发

  • onDragLessThreshold{Function} @default = null

    下拉距离小于阈值 hook:手指触碰屏幕然后滑动时触发;下拉距离从大于阈值到小于阈值时触发

  • onDragGreaterThreshold{Function} @default = null

    下拉距离大于阈值 hook:下拉距离从小于阈值到大于阈值时触发

  • onDragDone - {Function} @default = null

    下拉加载(刷新) hook:手指离开屏幕并且下拉距离大于阈值时触发

  • onScrollToThreshold - {Function} @default = null

    滚动到阈值 hook:容器滚动到离底部还有阈值距离时触发

example

new Tractor({
  scroller: '.scroller',
  enableDragLoading: true,
  enableScrollLoading: true,
  dragThreshold: 50,
  scrollThreshold: 50,
  onDragStart: function () {
    console.log('onDragStart')
  },
  onDragLessThreshold: function () {
    console.log('onDragLessThreshold')
  },
  onDragGreaterThreshold: function () {
    console.log('onDragGreaterThreshold')
  },
  onDragDone: function () {
    console.log('onDragDone')
    // 加载新内容或刷新内容
  },
  onScrollToThreshold: function () {
    console.log('onScrollToThreshold')
    // 加载新内容
  }
})

LICENSE

MIT

tractor.js's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.