<div id="app" class="app"> <!-- page为单独的页面组件,page内可以编写任意的页面内容 --> <page :currentPage="currentPage"></page> <!-- page-controller为控制器组件 --> <page-controller :pageNum="pageNum" :currentPage="currentPage" @changePage="changePage" :arrowsType="arrowsType"></page-controller> </div>
/* 页面宽高为100%,overflow为hidden隐藏溢出部分 */
html,body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
.app {
height: 100%;
width: 100%;
}
<section class="page" v-if="options"
:style="{background:options.background,color:options.color||'#fff'}"
:class="{'page-before': options.index < currentPage,'page-after': options.index > currentPage}">
<div :class="{'page-center': options.isCenter}">
<slot></slot>
</div>
</section>
<section class="page" v-else>页面正在渲染中。。。</section>
.page {
position: absolute;
width: 100%;
height: 100%;
transition: all 0.5s ease 0s;
}
.page-before {
transform: translate3d(0,-100%,0);
}
.page-after {
transform: translate3d(0,100%,0);
}
<nav class="controller">
<button v-if="arrowsType != 'no'" class="prev-btn" :class="{moving:arrowsType === 'animate'}" @click="changePage(prevIndex)"></button>
<ul>
<li @click="changePage(index)" v-for="index in pageNum" :key="'controller-'+index" class="controller-item"></li>
</ul>
<button v-if="arrowsType != 'no'" class="next-btn" :class="{moving:arrowsType === 'animate'}" @click="changePage(nextIndex)"></button>
</nav>
changePage (index) {
this.$emit('changePage', index);
}
changePage (index) {
// 改变page
this.currentPage = index;
}
// PageController.vue
nextIndex () {
if (this.currentPage === this.pageNum) {
return 1;
} else {
return this.currentPage + 1;
}
},
prevIndex () {
if (this.currentPage === 1) {
return this.pageNum;
} else {
return this.currentPage - 1;
}
}
let _this = this;
let timer = null;
function scrollHandler (direction) {
// 防止重复触发滚动事件
if (timer != null) {
return;
}
if (direction === 'down') {
_this.changePage(_this.nextIndex);
} else {
_this.changePage(_this.prevIndex);
}
timer = setTimeout(function() {
clearTimeout(timer);
timer = null;
}, 500);
}
mounted () {
this.$children.forEach((child, index) => {
// 动态设置各个page内的options
if (child.option === null) {
let childOption = this.options[index];
this.$set(childOption,'index',index+1);
child.option = childOption;
}
});
}
changePage (index) {
// beforeLeave
let beforeIndex = this.currentPage - 1;
let leaveFunction = this.options[beforeIndex].beforeLeave;
typeof leaveFunction === 'function' && leaveFunction.call(this,this.$children[beforeIndex]);
// 改变page
this.currentPage = index;
// afterEnter
let nextIndex = index-1;
let enterFunction = this.options[nextIndex].afterEnter;
this.$nextTick(function () {
typeof enterFunction === 'function' && enterFunction.call(this,this.$children[nextIndex]);
})
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有