GithubHelp home page GithubHelp logo

davidmr001 / better-scroll Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ustbhuangyi/better-scroll

0.0 1.0 0.0 435 KB

inspired by iscroll, and it has a better scroll perfermance

Home Page: https://ustbhuangyi.github.io/better-scroll/

License: MIT License

JavaScript 91.10% CSS 2.85% HTML 6.05%

better-scroll's Introduction

better-scroll

npm

inspired by iscroll, and it has a better scroll perfermance https://ustbhuangyi.github.io/better-scroll/

立即使用

<body>
  <div id="wrapper">
    <ul>
	   <li>...</li>
	   <li>...</li>
	   ...
    </ul>
  </div>
<script type="text/javascript" src="better-scroll.js"></script>
<script type="text/javascript">
  new BScroll(document.getElementById('wrapper'));
</script>
</body>

搞定 !

通过npm引入

安装better-scroll

npm install better-scroll --save-dev

引入better-scroll

import BScroll from 'better-scroll'

如果不支持import, 请使用

var BScroll = require('better-scroll')

DEMO

better-scroll 的源码是基于 Webpack 构建的

首先,clone项目源码

git clone https://github.com/ustbhuangyi/better-scroll.git

安装依赖

cd better-scroll
npm install

测试demo页

npm run dev

打开浏览器访问如下地址, 查看效果

localhost:9090

Options 参数

Example:

let scroll = new BScroll(document.getElementById('wrapper'), {
  startX: 0,
  startY: 0
})

Options List:

  • startX: 0 开始的X轴位置
  • startY: 0 开始的Y轴位置
  • scrollY: true 滚动方向
  • click: true 是否启用click事件
  • directionLockThreshold: 5
  • momentum: true 是否开启拖动惯性
  • bounce: true 是否启用弹力动画效果,关掉可以加速
  • selectedIndex: 0
  • rotate: 25
  • wheel: false 该属性是给 picker 组件使用的,普通的列表滚动不需要配置
  • snap: false 是否开启捕捉元素,当为 true 时,捕捉的元素会根据可滚动的位置和滚动区域计算得到可滑动几页。
  • snapLoop: false 是否创建当前滚动元素子集的拷贝
  • snapThreshold: 0.1 滑动的长度限制,只有大于这个距离才会触发事件
  • swipeTime: 2500 swipe 持续时间
  • bounceTime: 700 弹力动画持续的毫秒数
  • adjustTime: 400
  • swipeBounceTime: 1200
  • deceleration: 0.001 滚动动量减速越大越快,建议不大于0.01
  • momentumLimitTime: 300 惯性拖动的回弹时间
  • momentumLimitDistance: 15 惯性拖动的回弹距离
  • resizePolling: 60 重新调整窗口大小时,重新计算better-scroll的时间间隔
  • probeType: 1 监听事件的触发时间,1为即时触发,3为延迟到事件完毕后触发
  • preventDefault: true 是否阻止默认事件
  • preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/ } 阻止默认事件
  • HWCompositing: true 是否启用硬件加速
  • useTransition: true 是否使用CSS3的Transition属性,否则使用-requestAnimationFram代替
  • useTransform: true 是否使用CSS3的Transform属性
  • probeType: 1 滚动的时候会派发scroll事件,会截流。2滚动的时候实时派发scroll事件,不会截流。 3除了实时派发scroll事件,在swipe的情况下仍然能实时派发scroll事件

Events 事件

Example:

let scroll = new BScroll(document.getElementById('wrapper'),{
   probeType: 3
})

scroll.on('scroll', (pos) => {
  console.log(pos.x + '~' + posx.y)
  ...
})

Events 列表

  • beforeScrollStart - 滚动开始之前触发
  • scrollStart - 滚动开始时触发
  • scroll - 滚动时触发
  • scrollCancel - 取消滚动时触发
  • scrollEnd - 滚动结束时触发
  • flick - 触发了 fastclick 时的回调函数
  • refresh - 当 better-scroll 刷新时触发
  • destroy - 销毁 better-scroll 实例时触发

派发滚动

  • scrollTo(x, y, time, easing)

Example:

let scroll = new BScroll(document.getElementById('wrapper'))
scroll.scrollTo(0, 500)
...

better-scroll's People

Contributors

ustbhuangyi avatar

Watchers

 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.