一个基于vue2.x fullpage 插件 支持移动端和pc端
npm install fullpage-vue --save
如果你想使用动画指令,请安装animate.css
npm install animate.css --save
start
: (default:0
) 默认显示那一页duration
: (default:500
)loop
: (default:false
)dir
: (default:v
) 运动的方向v
垂直 和h
水平der
: (default:0.1
)movingFlag
: (default:false
)beforeChange
: (default:function
) 页面切换前回调afterChange
: (default:function
) 页面切换后回调overflow
: (default:hidden
) hidden || scroll || auto 处理page中的滚动条hidden
隐藏滚动条scroll
处理page的滚动条auto
处理page中所有元素的滚动条,从触发元素开始检查
移动到指定页面
/**
*
* @param {Number} moveToIndex 移动到指定坐标
* @param {Boolean} animated 是否有动画
* @param {Boolean} force 是否强制移动,忽略disable
*/
$fullpage.moveTo(1,false ,true)
移动到上一个页面
移动到下一个页面
改变disabled
的值,当值=true则禁止滑动
改变Dom的结构,需要调用更新。例如:通过v-for
和v-if
影响page的数量都需要调用$update
更新。
<button type="button"
v-for="btn in pageNum"
:class="{active:index == btn + 2}"
@click="moveTo(btn+2)">page {{btn+2}}</button>
<button type="button" @click="showPage()">add page</button>
<div class="page-2 page" v-for="page in pageNum">
<h2 class="part-2" v-animate="{value: 'bounceInRight'}">page {{page}}</h2>
</div>
showPage:function(){
this.pageNum ++;
this.$refs.fullpage.$fullpage.$update();
}
在main.js需要引入该插件的css和js文件
import 'fullpage-vue/src/fullpage.css'
import VueFullpage from 'fullpage-vue'
Vue.use(VueFullpage)
template
在page-wp
容器上加v-fullpage
指令,v-fullpage
的值是fullpage的配置
在page
容器上加v-animate
指令,v-animate
的值是animate.css
的动画效果
<div class="fullpage-container">
<div class="fullpage-wp" v-fullpage="opts" ref="example">
<div class="page-1 page">
<p class="part-1" v-animate="{value: 'bounceInLeft'}">fullpage-vue</p>
</div>
<div class="page-2 page">
<p class="part-2" v-animate="{value: 'bounceInRight'}">fullpage-vue</p>
</div>
<div class="page-3 page">
<p class="part-3" v-animate="{value: 'bounceInLeft', delay: 0}">fullpage-vue</p>
<p class="part-3" v-animate="{value: 'bounceInRight', delay: 600}">fullpage-vue</p>
<p class="part-3" v-animate="{value: 'zoomInDown', delay: 1200}">fullpage-vue</p>
</div>
</div>
<button @click="moveNext">next</button>
</div>
js
fullpage-vue
的值请参考api文档
export default {
data() {
return {
opts: {
start: 0,
dir: 'v',
duration: 500,
beforeChange: function (currentSlideEl,currenIndex,nextIndex) {
},
afterChange: function (currentSlideEl,currenIndex,nextIndex) {
}
}
}
},
methods:{
moveNext(){
this.$refs.example.$fullpage.moveNext(); //Move to the next page
}
}
}
style
page-container
需要固定宽度和高度,fullpage
会自适应父元素的宽度和高度。
如下设置可使滚动页面充满全屏
<style>
.page-container {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
</style>