# 安装

# NPM

BetterScroll 托管在 NPM 上,执行如下命令安装:

npm install @better-scroll/core --save

// or

yarn add @better-scroll/core

接下来就可以在代码中引入了,webpack 等构建工具都支持从 node_modules 里引入代码:

import BScroll from '@better-scroll/core'

如果是 commonjs 的语法,如下:

var BScroll = require('@better-scroll/scroll')

# script 加载

BetterScroll 也支持直接用 script 加载的方式,加载后会在 window 上挂载一个 BScroll 的对象。

<script src="https://unpkg.com/@better-scroll/core@latest/dist/core.js"></script>

<!-- minify -->
<script src="https://unpkg.com/@better-scroll/core@latest/dist/core.min.js"></script>
let wrapper = document.getElementById("wrapper")
let bs = new BScroll(wrapper, {})

# 具备所有插件能力的 BetterScroll

npm install better-scroll --save

// or

yarn add better-scroll
import BetterScroll from 'better-scroll'
let bs = new BetterScroll('.wrapper', {})

也可以通过 CDN 加载。

<script src="https://unpkg.com/better-scroll@latest/dist/better-scroll.js"></script>

<!-- minify -->
<script src="https://unpkg.com/better-scroll@latest/dist/better-scroll.min.js"></script>
let bs = BetterScroll.createBScroll('.wrapper', {})