jQuery创建令人印象深刻 单页滚动体验

  • 源码大小:10.02KB
  • 所需积分:1积分
  • 源码编号:19JP-3528
  • 浏览次数:725次
  • 最后更新:2023年06月23日
  • 所属栏目:动画
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

在过去的几年里,单页滚动网站变得相当流行。它们给你一个很好的外观和感觉,在自然界中更具互动性。如果你想为自己制作一个,但又不想从头开始编写整个网站的代码,那么最简单的方法之一就是安装一个单页滚动插件。

jFullPageScroller是一个jQuery插件,它可以在您的网络应用程序或登录页上创建令人印象深刻、平滑和可配置的水平或垂直单页滚动体验。非常适合在移动设备或平板电脑等较小屏幕上显示长内容。它完全基于jQuery animate()方法构建,在现代浏览器和旧版本的IE中具有交叉兼容的性能。

如何使用它:

1.在HTML中添加页面部分。可用的HTML属性:

  • jfps剖面方向:设置页面的滚动方向:“水平”或“垂直”。
  • jfps部分:每个部分的必需属性。
  • jfps部分id:为每个部分指定一个唯一的ID。如果您有页眉导航,则为必填项。
  1. <main jfps-section-direction="vertical">
  2. <section jfps-section jfps-section-id="section-1">
  3. <div>
  4. <h1>Section #1</h1>
  5. </div>
  6. </section>
  7. <section jfps-section jfps-section-id="section-2">
  8. <div>
  9. <h1>Section #2</h1>
  10. </div>
  11. </section>
  12. <section jfps-section jfps-section-id="section-3">
  13. <div>
  14. <h1>Section #3</h1>
  15. </div>
  16. </section>
  17. <section jfps-section jfps-section-id="section-4">
  18. <div>
  19. <h1>Section #4</h1>
  20. </div>
  21. </section>
  22. <section jfps-section jfps-section-id="section-5">
  23. <div>
  24. <h1>Section #5</h1>
  25. </div>
  26. </section>
  27. </main>

2.创建一个标题导航栏,其中包含指向页面上不同内容部分的锚链接。可选。

  1. <header id="demo-header">
  2. <nav>
  3. <a jfps-nav jfps-target-section="section-1" href="#section-1">Section #1</a>
  4. <a jfps-nav jfps-target-section="section-2" href="#section-2">Section #2</a>
  5. <a jfps-nav jfps-target-section="section-3" href="#section-3">Section #3</a>
  6. <a jfps-nav jfps-target-section="section-4" href="#section-4">Section #4</a>
  7. <a jfps-nav jfps-target-section="section-5" href="#section-5">Section #5</a>
  8. </nav>
  9. </header>
  1. /* example CSS */
  2. #demo-header {
  3. padding: 1rem;
  4. position: fixed;
  5. text-align: center;
  6. top: 0;
  7. width: 100%;
  8. z-index: 10;
  9. }
  10.  
  11. #demo-header a {
  12. color: #333;
  13. cursor: pointer;
  14. font-size: 1rem;
  15. margin: 0 1rem;
  16. text-decoration: none;
  17. }
  18.  
  19. #demo-header a.active {
  20. text-decoration: underline;
  21. }
  22.  
  23. #demo-header a:hover {
  24. text-decoration: underline;
  25. }

3.将jQuery库和jFullPageScroller插件的文件添加到HTML页面。

  1. <link href="/path/to//dist/jFullPageScroller.min.css" rel="stylesheet" />
  2. <script src="/path/to/cdn/jquery.slim.min.js"></script>
  3. <script src="/path/to//dist/jFullPageScroller.min.js"></script>

4.初始化插件并完成。

  1. $.jFullPageScroller({
  2. // options
  3. });

5.配置平滑滚动动画。

  1. $.jFullPageScroller({
  2. animationDelay: 0,
  3. animationSpeed: 1000,
  4. });

6.确定是否允许使用箭头键滚动页面。默认值:true。

  1. $.jFullPageScroller({
  2. enableKeyPressScroll: true,
  3. });

7.确定是否启用页眉导航。默认值:false。

  1. $.jFullPageScroller({
  2. withNavigation: true,
  3. });

8.在滚动页面部分时触发一个功能。

  1. $.jFullPageScroller({
  2. // options
  3. }, function() {
  4. // Section #1 Callback
  5. }, function() {
  6. // Section #2 Callback
  7. }, function() {
  8. // Section #3 Callback
  9. }, function() {
  10. // Section #4 Callback
  11. }, function() {
  12. // Section #5 Callback
  13. });

更新日志:

v1.3(2022年12月6日)

  • 改进了回调功能。
  • 主要修复和改进。

v1.2(2022年10月6日)

  • 小的修复和改进。

v1.1(2022年5月6日)

  • 修正了在移动设备上滚动不起作用的错误。
  • 主要修复和改进。

预览截图