开源项目 Smooth Scroll 使用教程

开源项目 Smooth Scroll 使用教程

smooth-scrollSmooth collection scrolling项目地址:https://gitcode.com/gh_mirrors/smoo/smooth-scroll

1. 项目的目录结构及介绍

Smooth Scroll 项目的目录结构如下:

smooth-scroll/
├── dist/
│   ├── smooth-scroll.min.js
│   └── smooth-scroll.polyfills.min.js
├── src/
│   ├── smooth-scroll.js
│   └── smooth-scroll.polyfills.js
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── gulpfile.js
├── index.html
├── jump-to-top.html
├── package-lock.json
├── package.json
├── rollup.config.js
└── speed.html

目录介绍

  • dist/:包含编译后的生产环境代码,包括 smooth-scroll.min.jssmooth-scroll.polyfills.min.js
  • src/:包含开发环境的源代码,包括 smooth-scroll.jssmooth-scroll.polyfills.js
  • .gitignore:Git 忽略文件配置。
  • .travis.yml:Travis CI 配置文件。
  • LICENSE:项目许可证。
  • README.md:项目说明文档。
  • gulpfile.js:Gulp 构建脚本。
  • index.html:示例页面。
  • jump-to-top.html:返回顶部示例页面。
  • package-lock.json:NPM 锁定文件。
  • package.json:NPM 配置文件。
  • rollup.config.js:Rollup 配置文件。
  • speed.html:速度测试示例页面。

2. 项目的启动文件介绍

Smooth Scroll 项目的启动文件主要是 dist/ 目录下的 smooth-scroll.min.jssmooth-scroll.polyfills.min.js

启动文件介绍

  • smooth-scroll.min.js:独立版本,不包含 polyfills。
  • smooth-scroll.polyfills.min.js:包含 polyfills 的版本,支持 closest()requestAnimationFrame()CustomEvent()

在 HTML 文件中引入启动文件:

<script src="dist/smooth-scroll.min.js"></script>

<script src="dist/smooth-scroll.polyfills.min.js"></script>

3. 项目的配置文件介绍

Smooth Scroll 项目的配置文件主要是 package.jsonrollup.config.js

配置文件介绍

  • package.json:包含项目的元数据和依赖项。
{
  "name": "smooth-scroll",
  "version": "15.0.0",
  "description": "A lightweight script to animate scrolling to anchor links.",
  "main": "dist/smooth-scroll.polyfills.min.js",
  "scripts": {
    "build": "gulp build"
  },
  "dependencies": {},
  "devDependencies": {
    "gulp": "^4.0.2",
    "rollup": "^2.3.4"
  }
}
  • rollup.config.js:Rollup 打包配置文件。
import { terser } from 'rollup-plugin-terser';

export default {
  input: 'src/smooth-scroll.js',
  output: {
    file: 'dist/smooth-scroll.min.js',
    format: 'iife',
    name: 'SmoothScroll',
    plugins: [terser()]
  }
};

通过这些配置文件,可以进行项目的构建和打包。

smooth-scrollSmooth collection scrolling项目地址:https://gitcode.com/gh_mirrors/smoo/smooth-scroll

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

任凝俭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值