基于jquery实现全屏滚动效果

那么今天就来介绍这款fullPage,与fullPage.js是不同的,fullpage兼容性更佳,能向下兼容到IE6, 不依赖任何 js 库,可独立使用。功能上虽然不如 fullPage.js 强大,但一般使用已经足够了,尤其是它的动画效果,你可以自由设定缩放、旋转以产生各种各样的动画效果。同时它还支持 fullPage.js 所没有的水平滚动。

兼容桌面端(ie5.5+) 和 手机端

你可以用它来构建你的个人主页或者网页应用

这是一个不使用jQuery小巧的框架 不到9KB

再介绍之前先看一看运行效果图:

基于jquery实现全屏滚动效果

引入核心库,pagefull的依赖任何JS库,所以只需引入它本身就可以了

<script src="https://www.jb51.net/js/fullPage.min.js"></script>

写入html

//请在head区加入以下代码,移动端使用 <meta content="width=device-width,initial-scale=1,maximum-scale=1"> <!--[if lte IE 7]> <body scroll="no"> <![endif]--> <!--[if gt IE 7]><!--> <body> <!--<![endif]--> <div> <div> <div> </div> </div> <div> <div> </div> </div> <div data-step="4"> <div> <p>data-step可以让你在不切屏的情况下更换动画</p> </div> </div> <div> <div> </div> </div> <div> <div> </div> </div> <div> <div> </div> </div> </div> <ul> <li>0</li> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> </body>

写入CSS,不熟悉CSS3的朋友请回去补下,这里不做解析了,CSS可以根据项目的需求自由的定义。

html { -ms-touch-action: none; /* 阻止windows Phone 的默认触摸事件 */ } body, div, p { margin: 0; padding: 0; } ul { list-style: none; } body { width: 100%; *cursor: default; overflow: hidden; font: 16px/1.5 "Microsoft YaHei",Helvetica,STHeiti STXihei,Microsoft JhengHei,Arial; } #pageContain { overflow: hidden; } .page { display: none; width: 100%; height: 100%; overflow: hidden; position: absolute; top: 0; left: 0; } .contain { width: 100%; height: 100%; display: none; position: relative; z-index: 0; } .current .contain,.slide .contain { display: block; } .current { display: block; z-index: 1; } .slide { display: block; z-index: 2; } .swipe { display: block; z-index: 3; transition-duration: 0ms !important; -webkit-transition-duration: 0ms !important; } .page1 { background: #37c1e3; } .page2 { background: #009922; } .page3 { background: #992211; } .page4 { background: #ff00ff; } .page5 { background: #00ff00; } .page6 { background: #22ffff; } #navBar { z-index: 3; position: absolute; top: 10%; right: 3%; } #navBar .active { background: #ccc; } #navBar li { cursor: pointer; margin-bottom: 10px; transition: all .7s ease; border-radius: 50%; line-height: 40px; text-align: center; width: 40px; height: 40px; } p { width: 200px; height: 100px; color:#fff; text-align: center; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -50px; opacity: 1; transition: all .8s ease; transform-origin: 50% 50%; } .step1 p { transform: translate(0, -50px); -webkit-transform: translate(0, -50px); } .step2 p { opacity: 0; transform: scale(2); -webkit-transform: scale(2); } .step3 p { transform: scale(1); -webkit-transform: scale(1) opacity: 1; } .step4 p { -webkit-transform: rotate(360deg) translate(0,-200px) scale(.3); transform: rotate(360deg) translate(0,-200px) scale(.3); opacity: 0; }

写入JS,实现效果

var runPage; runPage = new FullPage({ id : 'pageContain', // 容器id slideTime : 800, // 每页切换时间,单位为毫秒 continuous : false, // 是否循环(即能从最后页跳到第一页面) effect : { // 滚动效果 transform : { translate : 'Y', // 'X'|'Y'|'XY'|'none' X轴|Y轴|XY轴|无 scale : [.1, 1], // [scalefrom, scaleto] [起始缩放比例, 结束时缩放比例] rotate : [0, 0] // [rotatefrom, rotateto] [起始旋转角度, 结束时旋转角度] }, opacity : [0, 1] // [opacityfrom, opacityto][起始透明度, 结束时透明度] }, mode : 'wheel,touch,nav:navBar', // 转换模式 'wheel,touch,nav:navBar' 表示 '滚轮,触摸,导航条:导航条id' easing : 'ease' // easing('ease','ease-in','ease-in-out' 或使用贝塞尔曲线 [.33, 1.81, 1, 1]; // ,onSwipeStart : function(index, thisPage) { // 触摸开始时的回调函数 // return 'stop'; // } // ,beforeChange : function(index, thisPage) { // 滑动开始时的回调函数 // return 'stop'; // } // ,callback : function(index, thisPage) { // 滑动结束后的回调函数 // alert(index); // }; });

详细参数设置

id String – 外层包裹id

slideTime Integer (default:800) – 每页切换时间(毫秒)

effect Object (default:{}) – 效果参数

mode String (default:'') – 转换模式 'wheel,touch,nav:navBar' 表示 '滚轮,触摸,导航条:导航条id'

callback Function – 滑动结束后的回调函数

接口

Fullpage也提供了一些借口供使用此插件的开发者调用:

prev() 直接滑向上一页

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgzgpg.html