# hv-scroll

> horizon & vertical scroll

Latest version **1.1.2** (published 2017-01-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install hv-scroll
pnpm add hv-scroll
yarn add hv-scroll
bun add hv-scroll
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2017-01-22 |
| First published | 2017-01-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | xiuhong |
| Maintainers | xiuhong |
| Keywords | horizon, vertical, scroll |

## Links

- npm: https://www.npmjs.com/package/hv-scroll
- Repository: https://github.com/xiuhonglee/hv-scroll
- Homepage: https://github.com/xiuhonglee/hv-scroll#readme
- Issues: https://github.com/xiuhonglee/hv-scroll/issues
- npm.io page: https://npm.io/package/hv-scroll

## Dependencies (1)

- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.20.0

## Recent versions

- 1.1.2 (latest) — 2017-01-22
- 1.1.1 — 2017-01-22
- 1.1.0 — 2017-01-20
- 1.0.9 — 2017-01-20
- 1.0.8 — 2017-01-20
- 1.0.7 — 2017-01-20
- 1.0.6 — 2017-01-19
- 1.0.5 — 2017-01-19
- 1.0.4 — 2017-01-18

## README

## hv-scroll

### 1. 使用姿势
####1.1 template
```html
<div id="container">
  <div class="slider-item">
    <div class="item">1</div>
  </div>
  <div class="slider-item">
    <div class="item">2</div>
  </div>
  <div class="slider-item">
    <div class="item">3</div>
  </div>
</div>
```

#### 1.2 javascript
```javascript
const container = document.querySelector('#container')

const vHScroll = new window.HVScroll(container, {
  afterInitialize: function() {
    container.style.visibility = 'visible'
  }
})
```

### 2. 通过npm引入
####2.1 安装hv-scroll
```shell
$ npm install hv-scroll
```

####2.2 引入hv-scroll
```shell
$ import HVScroll from 'hv-scroll'
```

### 3. Demo
####3.1 下载项目源码
**源码基于webpack构建**
```shell
$ git clone https://github.com/xiuhonglee/hv-scroll.git
```

####3.2 安装依赖
```shell
$ cd hv-scroll
$ npm install 
```

####3.3 测试Demo页
```shell
$ npm run dev
```

####3.4 浏览器打开
```shell
localhost:9090
```


### 4. Options参数
**opitons list (第一个为默认值)**

#### 4.1 属性值
* pageClass: [ className ] slider元素类名，上例为slider-item
* direction: [ 'horizontal' | 'vertical' ] 滚动方向，默认：horizontal
* minDragDistance: [ 40 ] 切换轮播的最小滚动距离，单位px，默认40
* itemsInPage: [ 1 ] 对slider进行分割，默认为1，表示不分割
* moveStep: [ 'page' | 'slider' ] 当itemsInPage > 1时，该值设为slider，轮播将按照窗格进行滚动
* page: [ 1 ] 初始化显示页数，起始值为1
* duration: [ 300 ] 动画时长，单位: ms

#### 4.2 方法
**供外部调用接口**
```javascript
const vHScroll = new window.HVScroll(container, {
  afterInitialize: function() {
    container.style.visibility = 'visible' // 必要！
  },

  // 滑动slider时的调用顺序: onDragStart -> onDrag -> onSwipeStart -> onDragEnd -> onSwipeEnd

  onSwipeStart: function(container, activeElement, currentPageIndex, direction) {
    // 1. container: 容器DOM
    // 2. acttiveElement: 当前活动元素（最左/上的那个slider元素）
    // 3. currentPageIndex: 当前slider索引值
    // 4. direction: 滑动方向（left | right | top | bottom）
  },

  onSwipeEnd: function(container, activeElement, currentPage, direction) {
    // 参数onSwipeStart
  },

  onDragStart: function(event) {
    // event: 事件对象
  },
  onDrag: function (activeElement, parsedEvent, overscroll, event) {
    // 1. activeElement: 当前活动元素（最左/上的那个slider元素）
    // 2. parsedEvent: {
    //      direction: 'left | right | top | bottom',
    //      distanceX: Number,
    //      distanceY: Number
    //    }
    // 3. overscroll: Boolean，是否越界; 比如：是否滑动最左侧
    // 4. event: 事件对象
  },
  onDragEnd: function (container, activeElement, currentPageIndex, direction) {
    // 参数onSwipeStart
  }
})
```

---
_Source: https://npm.io/package/hv-scroll · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
