UNPKG

3.71 kBMarkdownView Raw
1# fullpage-vue
2
3一个基于vue2.x fullpage 插件 支持移动端和pc端
4
5## 在线demo
6[jsfiddle demo](https://jsfiddle.net/e23jiang/6jc3okaq/1/)
7
8## 安装
9```
10npm install fullpage-vue --save
11```
12如果你想使用动画指令,请安装``animate.css``
13```
14npm install animate.css --save
15```
16[animate.css用法](https://daneden.github.io/animate.css/)
17
18## 文档
19
20### 选项
21
22- `start` : (default:`0`) 默认显示那一页
23- `duration` : (default:`500`)
24- `loop` : (default:`false`)
25- `dir` : (default:`v`) 运动的方向 `v` 垂直 和 `h` 水平
26- `der` : (default:`0.1`)
27- `movingFlag` : (default:`false`)
28- `beforeChange` : (default:`function`) 页面切换前回调
29- `afterChange` : (default:`function`) 页面切换后回调
30- `overflow` : (default:`hidden`) hidden || scroll || auto 处理page中的滚动条
31 `hidden` 隐藏滚动条
32 `scroll` 处理page的滚动条
33 `auto` 处理page中所有元素的滚动条,从触发元素开始检查
34
35### method
36
37#### moveTo
38 移动到指定页面
39
40#### movePrev
41 移动到上一个页面
42
43#### moveNext
44 移动到下一个页面
45
46#### setDisabled
47 改变`disabled`的值,当值=true则禁止滑动
48
49#### $upadte
50 改变Dom的结构,需要调用更新。例如:通过`v-for``v-if`影响page的数量都需要调用`$update`更新。
51
52```html
53 <button type="button"
54 v-for="btn in pageNum"
55 :class="{active:index == btn + 2}"
56 @click="moveTo(btn+2)">page {{btn+2}}</button>
57 <button type="button" @click="showPage()">add page</button>
58
59 <div class="page-2 page" v-for="page in pageNum">
60 <h2 class="part-2" v-animate="{value: 'bounceInRight'}">page {{page}}</h2>
61 </div>
62```
63```js
64 showPage:function(){
65 this.pageNum ++;
66 this.$refs.fullpage.$fullpage.$update();
67 }
68```
69
70## 快速上手
71
72#### main.js
73在main.js需要引入该插件的css和js文件
74
75```js
76import 'fullpage-vue/src/fullpage.css'
77import VueFullpage from 'fullpage-vue'
78Vue.use(VueFullpage)
79```
80
81#### app.vue
82
83**template**
84
85``page-wp``容器上加``v-fullpage``指令,``v-fullpage``的值是fullpage的配置
86``page``容器上加``v-animate``指令,``v-animate``的值是``animate.css``的动画效果
87```html
88<div class="fullpage-container">
89 <div class="fullpage-wp" v-fullpage="opts" ref="example">
90 <div class="page-1 page">
91 <p class="part-1" v-animate="{value: 'bounceInLeft'}">fullpage-vue</p>
92 </div>
93 <div class="page-2 page">
94 <p class="part-2" v-animate="{value: 'bounceInRight'}">fullpage-vue</p>
95 </div>
96 <div class="page-3 page">
97 <p class="part-3" v-animate="{value: 'bounceInLeft', delay: 0}">fullpage-vue</p>
98 <p class="part-3" v-animate="{value: 'bounceInRight', delay: 600}">fullpage-vue</p>
99 <p class="part-3" v-animate="{value: 'zoomInDown', delay: 1200}">fullpage-vue</p>
100 </div>
101 </div>
102 <button @click="moveNext">next</button>
103</div>
104```
105
106**js**
107
108``fullpage-vue``的值请参考[api文档](https://github.com/river-lee/vue-fullpage#options)
109```js
110export default {
111 data() {
112 return {
113 opts: {
114 start: 0,
115 dir: 'v',
116 duration: 500,
117 beforeChange: function (currentSlideEl,currenIndex,nextIndex) {
118 },
119 afterChange: function (currentSlideEl,currenIndex,nextIndex) {
120 }
121 }
122 }
123 },
124 methods:{
125 moveNext(){
126 this.$refs.example.$fullpage.moveNext(); //Move to the next page
127 }
128 }
129}
130```
131
132**style**
133``page-container``需要固定宽度和高度,``fullpage``会自适应父元素的宽度和高度。
134如下设置可使滚动页面充满全屏
135```
136<style>
137.page-container {
138 position: absolute;
139 left: 0;
140 top: 0;
141 width: 100%;
142 height: 100%;
143}
144</style>
145```