[关闭]
@kexinWeb 2017-03-04T09:37:52.000000Z 字数 5386 阅读 2143

fullPage.js 插件使用

fullpage plugin


写在前面

fullPage插件是基于jquery框架开发的一个全屏滚动插件,它能够很轻松很方便地做出漂亮的全屏单页网站。

下载安装

引入fullPage文件

  1. <link rel="stylesheet" href="css/jquery.fullPage.css">
  2. <script src="js/jquery.min.js"></script>
  3. <script src="js/jquery.fullPage.js"></script>
  1. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.9.3/jquery.fullpage.css">
  2. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  3. <script src="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.9.3/jquery.fullpage.js"></script>

注意: 由于fullpage插件依赖于jquery框架,所以jquery框架要在fullpage前面引用。

开始一个简单的fullpage项目

1.页面结构

  1. <div id='fullpage'>
  2. <div class="section">第一屏</div>
  3. <div class="section">
  4. <div class="slide"> slide1 </div>
  5. <div class="slide"> slide2 </div>
  6. <div class="slide"> slide3 </div>
  7. </div>
  8. <div class="section">第三屏</div>
  9. <div class="section">第四屏</div>
  10. <div class="section">第五屏</div>
  11. </div>

2.js代码

  1. <script type="text/javascript">
  2. $(function() {
  3. $('#fullpage').fullpage();
  4. });
  5. </script>

配置项

  1. //当页面加载完毕之后执行函数
  2. $(document).ready(function() {
  3. //配置fullpage
  4. $('#fullpage').fullpage({
  5. //Navigation
  6. menu: false,//绑定菜单,设定的相关属性与 anchors 的值对应后,菜单可以控制滚动
  7. lockAnchors: false,//锁定锚链接不随页面滑动而改变
  8. anchors:['firstPage', 'secondPage'],//锚链接,数组中元素对应各个页面的锚链接
  9. navigation: false,//有无导航栏
  10. navigationPosition: 'right',//导航栏位置
  11. navigationTooltips: ['firstSlide', 'secondSlide'],//导航栏提示文字,与页面一一对应
  12. showActiveTooltip: false,//是否显示当前页面提示文字
  13. slidesNavigation: true,//有无幻灯片(横向)导航栏
  14. slidesNavPosition: 'bottom',//幻灯片(横向)导航栏位置
  15. //Scrolling
  16. css3: true,//是否支持css3动画
  17. scrollingSpeed: 700,//滚动速度,以毫秒为单位
  18. autoScrolling: true,//是否自动滑动
  19. fitToSection: true,//每一屏是否自动适应视窗(viewport)大小
  20. scrollBar: false,//是否有滚动条
  21. easing: 'easeInOutCubic',//全屏滚动效果,需要jquery.easing.js或者jqueryUI的支持
  22. easingcss3: 'ease',//css3动画过度效果
  23. loopBottom: false,
  24. loopTop: false,
  25. loopHorizontal: true,
  26. continuousVertical: false,
  27. normalScrollElements: '#element1, .element2',//设置不受默认滚动行为限制的正常滚动的元素
  28. scrollOverflow: false,//页面内容溢出后是否隐藏
  29. touchSensitivity: 15,//触摸敏感度
  30. normalScrollElementTouchThreshold: 5,
  31. //Accessibility
  32. keyboardScrolling: true,
  33. animateAnchor: true,
  34. recordHistory: true,//是否把滚动状态记入浏览器的历史记录里
  35. //Design
  36. controlArrows: true,//幻灯片滚动控制箭头
  37. verticalCentered: true,//section内容是否垂直居中
  38. resize : false,//字体大小是否根据窗口大小
  39. sectionsColor : ['#ccc', '#fff'],//每一页的背景颜色
  40. paddingTop: '3em',//section内上边距
  41. paddingBottom: '10px',//section内下边距
  42. fixedElements: '#header, .footer',//固定的元素,如主导航栏
  43. responsiveWidth: 0,
  44. responsiveHeight: 0,//官方文档:A normal scroll (autoScrolling:false) will be used under the defined height in pixels. A class fp-responsive is added to the body tag in case the user wants to use it for his own responsive CSS. For example, if set to 900, whenever the browser's height is less than 900 the plugin will scroll like a normal site.
  45. //Custom selectors
  46. sectionSelector: '.section',//当页面重新加载的时候直接定位到指定的section
  47. slideSelector: '.slide',//当页面重新加载的时候直接定位到指定的slide
  48. //callback
  49. onLeave: function(index, nextIndex, direction){},//离开section
  50. afterLoad: function(anchorLink, index){},//加载完section
  51. afterRender: function(){},//渲染整个页面后
  52. afterResize: function(){},//重新resize之后
  53. afterSlideLoad: function(anchorLink, index, slideAnchor, slideIndex){},//加载完某一个slide后 slideIndex)
  54. onSlideLeave: function(anchorLink, index, slideIndex, direction, nextSlideIndex){}//离开某一个slide后
  55. });
  56. });

方法

1.moveSectionUp()

$.fn.fullpage.moveSectionUp();

2.moveSectionDown()

$.fn.fullpage.moveSectionDown();

3.moveTo(section, slide)

$.fn.fullpage.moveTo('firstSlide', 2);

$.fn.fullpage.moveTo(3, 0);

4.silentMoveTo(section, slide)

$.fn.fullpage.silentMoveTo('firstSlide', 2);

5.moveSlideLeft()

$.fn.fullpage.moveSlideLeft();

moveSlideRight()也是如此

$.fn.fullpage.moveSlideRight();

6.setAutoScrolling(boolean)

$.fn.fullpage.setAutoScrolling(false);

7.setFitToSection(boolean)

$.fn.fullpage.setFitToSection(false);

8.setLockAnchors(boolean)

$.fn.fullpage.setLockAnchors(false);

9.setAllowScrolling(boolean, [directions])

10.setKeyboardScrolling(boolean, [directions])

11.setRecordHistory(boolean)

$.fn.fullpage.setRecordHistory(false);

12.setScrollingSpeed(milliseconds)

$.fn.fullpage.setScrollingSpeed(700);

13.destroy(type)

$.fn.fullpage.destroy();

destroying all Javascript events and any modification done by fullPage.js over your original HTML markup.

$.fn.fullpage.destroy('all');

14.reBuild()

$.fn.fullpage.reBuild();

关于menu的使用

  1. <ul id="myMenu">
  2. <li data-menuanchor="firstPage" class="active"><a href="#firstPage">First section</a></li>
  3. <li data-menuanchor="secondPage"><a href="#secondPage">Second section</a></li>
  4. <li data-menuanchor="thirdPage"><a href="#thirdPage">Third section</a></li>
  5. <li data-menuanchor="fourthPage"><a href="#fourthPage">Fourth section</a></li>
  6. </ul>
  1. $('#fullpage').fullpage({
  2. anchors: ['firstPage', 'secondPage', 'thirdPage', 'fourthPage', 'lastPage'],
  3. menu: '#myMenu'
  4. });

关于自定义Section高度

只需要给Section添加.fp-auto-height类就可以实现自定义高度。

参考资料

https://github.com/alvarotrigo/fullPage.js#options
https://www.uedsc.com/fullpage.html
http://www.uedsc.com/fullpage-introduction.html

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注