use-scroll-animate 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/CONTRIBUTING.md +76 -0
- package/LICENSE +21 -0
- package/README.md +214 -0
- package/README_ja.md +69 -0
- package/README_zh.md +69 -0
- package/dist/index.esm.js +697 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +708 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +14 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/types/core.d.ts +7 -0
- package/dist/types/index.d.ts +33 -0
- package/dist/types/presets.d.ts +15 -0
- package/dist/types/react.d.ts +18 -0
- package/dist/types/types.d.ts +123 -0
- package/dist/types/vue.d.ts +18 -0
- package/examples/react/App.tsx +61 -0
- package/examples/vanilla/index.html +201 -0
- package/package.json +35 -0
- package/rollup.config.js +41 -0
- package/src/core.ts +373 -0
- package/src/index.ts +48 -0
- package/src/presets.ts +148 -0
- package/src/react.ts +175 -0
- package/src/types.ts +161 -0
- package/src/vue.ts +118 -0
- package/tsconfig.json +17 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.2.0] - 2025-03-25
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Once Control**: New `once` option to automatically stop observing an element after its animation has triggered, saving system resources.
|
|
13
|
+
- **Viewport Offset**: New `offset` option to specify how many pixels an element must enter the viewport before the animation starts.
|
|
14
|
+
- **New Animation Presets**: Added `shimmer`, `pulse`, and `swing`.
|
|
15
|
+
- **Multi-language Documentation**: Added Chinese (`README_zh.md`) and Japanese (`README_ja.md`) documentation.
|
|
16
|
+
- **Fallback Support**: Added a fallback mechanism for browsers that do not support the Web Animations API.
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- **Memory Leak**: Improved `IntersectionObserver` cleanup by using `disconnect()` instead of `unobserve()` in key areas.
|
|
21
|
+
- **Stagger Bug**: Fixed an issue where `stagger` animation indices were incorrectly calculated when DOM elements were added dynamically.
|
|
22
|
+
- **Type Safety**: Improved TypeScript definitions for better developer experience.
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- Updated `AnimateOptions` and `ScrollAnimateConfig` to include `once` and `offset`.
|
|
27
|
+
- Refactored `IntersectionObserver` logic to handle offsets via `rootMargin`.
|
|
28
|
+
|
|
29
|
+
## [1.1.0] - 2025-03-25
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- **Multiple Animations**: Support for applying multiple animation presets simultaneously (e.g., `["fade-in-up", "zoom-in"]`).
|
|
34
|
+
- **Parallax Effect**: New `parallax` option for creating scroll-driven parallax effects (`x`, `y`, `rotate`, `scale`, `speed`).
|
|
35
|
+
- **Scroll Progress Listener**: New `onProgress` callback that provides real-time scroll progress (0 to 1) for an element.
|
|
36
|
+
- **New Animation Presets**: Added `skew-in`, `scale-x`, `scale-y`.
|
|
37
|
+
- **Threshold Array Support**: `threshold` option now accepts an array of numbers for more granular progress tracking.
|
|
38
|
+
- **Improved React Hooks**: `useScrollAnimate` and `useScrollStagger` now fully support `parallax` and `onProgress`.
|
|
39
|
+
- **Improved Vue Composables**: `useScrollAnimate` now fully supports `parallax` and `onProgress`.
|
|
40
|
+
|
|
41
|
+
## [1.0.0] - 2025-03-25
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- Initial release of `use-scroll-animate`.
|
|
46
|
+
- 16 built-in animation presets: `fade-in`, `fade-in-up`, `fade-in-down`, `fade-in-left`, `fade-in-right`, `zoom-in`, `zoom-out`, `flip-x`, `flip-y`, `slide-up`, `slide-down`, `slide-left`, `slide-right`, `bounce`, `rotate-in`, `blur-in`.
|
|
47
|
+
- Core `ScrollAnimate` singleton with `init()`, `observe()`, `unobserve()`, `animate()`, `destroy()`, `refresh()`, and `configure()` methods.
|
|
48
|
+
- HTML `data-sa` attribute API for zero-JS usage.
|
|
49
|
+
- React integration via `createReactHooks()` factory, providing `useScrollAnimate` and `useScrollStagger` hooks.
|
|
50
|
+
- Vue 3 integration via `createVueComposables()` factory, providing `useScrollAnimate` composable.
|
|
51
|
+
- Custom animation support via keyframe objects.
|
|
52
|
+
- `spring` easing preset (`cubic-bezier(0.34, 1.56, 0.64, 1)`).
|
|
53
|
+
- Stagger animation support for sibling elements.
|
|
54
|
+
- `onStart`, `onComplete`, `onEnter`, `onLeave` lifecycle callbacks.
|
|
55
|
+
- Full TypeScript support with comprehensive type definitions.
|
|
56
|
+
- Automatic `prefers-reduced-motion` detection and respect.
|
|
57
|
+
- Zero dependencies.
|
|
58
|
+
- ~2.9KB gzipped UMD bundle.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Contributing to use-scroll-animate
|
|
2
|
+
|
|
3
|
+
First off, thank you for considering contributing to `use-scroll-animate`! It's people like you that make the open-source community such a great place to learn, inspire, and create.
|
|
4
|
+
|
|
5
|
+
## Code of Conduct
|
|
6
|
+
|
|
7
|
+
By participating in this project, you are expected to uphold our Code of Conduct. Please treat everyone with respect and kindness.
|
|
8
|
+
|
|
9
|
+
## How Can I Contribute?
|
|
10
|
+
|
|
11
|
+
### Reporting Bugs
|
|
12
|
+
|
|
13
|
+
Before creating bug reports, please check the issue tracker as you might find out that you don't need to create one. When you are creating a bug report, please include as many details as possible:
|
|
14
|
+
|
|
15
|
+
* Use a clear and descriptive title for the issue to identify the problem.
|
|
16
|
+
* Describe the exact steps which reproduce the problem in as many details as possible.
|
|
17
|
+
* Provide specific examples to demonstrate the steps. Include links to files or GitHub projects, or copy/pasteable snippets, which you use in those examples.
|
|
18
|
+
* Describe the behavior you observed after following the steps and point out what exactly is the problem with that behavior.
|
|
19
|
+
* Explain which behavior you expected to see instead and why.
|
|
20
|
+
|
|
21
|
+
### Suggesting Enhancements
|
|
22
|
+
|
|
23
|
+
Enhancement suggestions are tracked as GitHub issues. When you are creating an enhancement suggestion, please include:
|
|
24
|
+
|
|
25
|
+
* Use a clear and descriptive title for the issue to identify the suggestion.
|
|
26
|
+
* Provide a step-by-step description of the suggested enhancement in as many details as possible.
|
|
27
|
+
* Provide specific examples to demonstrate the steps.
|
|
28
|
+
* Describe the current behavior and explain which behavior you expected to see instead and why.
|
|
29
|
+
* Explain why this enhancement would be useful to most users.
|
|
30
|
+
|
|
31
|
+
### Pull Requests
|
|
32
|
+
|
|
33
|
+
1. Fork the repo and create your branch from `main`.
|
|
34
|
+
2. If you've added code that should be tested, add tests.
|
|
35
|
+
3. If you've changed APIs, update the documentation.
|
|
36
|
+
4. Ensure the test suite passes.
|
|
37
|
+
5. Make sure your code lints.
|
|
38
|
+
6. Issue that pull request!
|
|
39
|
+
|
|
40
|
+
## Development Setup
|
|
41
|
+
|
|
42
|
+
1. Clone your fork:
|
|
43
|
+
```bash
|
|
44
|
+
git clone https://github.com/YOUR-USERNAME/use-scroll-animate.git
|
|
45
|
+
cd use-scroll-animate
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
2. Install dependencies:
|
|
49
|
+
```bash
|
|
50
|
+
npm install
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
3. Start the development build watcher:
|
|
54
|
+
```bash
|
|
55
|
+
npm run dev
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
4. Build the project:
|
|
59
|
+
```bash
|
|
60
|
+
npm run build
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Commit Messages
|
|
64
|
+
|
|
65
|
+
We follow the [Conventional Commits](https://www.conventionalcommits.org/) specification. Please ensure your commit messages adhere to this format:
|
|
66
|
+
|
|
67
|
+
* `feat:` A new feature
|
|
68
|
+
* `fix:` A bug fix
|
|
69
|
+
* `docs:` Documentation only changes
|
|
70
|
+
* `style:` Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
|
|
71
|
+
* `refactor:` A code change that neither fixes a bug nor adds a feature
|
|
72
|
+
* `perf:` A code change that improves performance
|
|
73
|
+
* `test:` Adding missing tests or correcting existing tests
|
|
74
|
+
* `chore:` Changes to the build process or auxiliary tools and libraries such as documentation generation
|
|
75
|
+
|
|
76
|
+
Thank you for your contribution!
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# use-scroll-animate 🚀
|
|
4
|
+
|
|
5
|
+
**A lightweight (~2.9KB gzipped), dependency-free scroll animation library for the modern web.**
|
|
6
|
+
|
|
7
|
+
[](https://github.com/HarrisonCN/use-scroll-animate/releases)
|
|
8
|
+
[](https://github.com/HarrisonCN/use-scroll-animate)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
[](http://makeapullrequest.com)
|
|
11
|
+
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
## Why `use-scroll-animate`?
|
|
15
|
+
|
|
16
|
+
In 2025, performance is everything. Traditional scroll animation libraries often bundle heavy dependencies, rely on outdated scroll event listeners, or force you into a specific framework.
|
|
17
|
+
|
|
18
|
+
`use-scroll-animate` is built differently:
|
|
19
|
+
- ⚡ **Zero Dependencies**: Pure Vanilla JS/TypeScript.
|
|
20
|
+
- 🚀 **High Performance**: Powered by `IntersectionObserver` and the native `Web Animations API`. No scroll event listeners, no layout thrashing.
|
|
21
|
+
- 🪶 **Ultra Lightweight**: Only ~2.9KB gzipped.
|
|
22
|
+
- 🧩 **Framework Agnostic**: Works seamlessly with Vanilla JS, React, Vue, Svelte, and more. First-class React Hooks and Vue Composables included.
|
|
23
|
+
- ♿ **Accessible**: Respects `prefers-reduced-motion` out of the box.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install use-scroll-animate
|
|
29
|
+
# or
|
|
30
|
+
yarn add use-scroll-animate
|
|
31
|
+
# or
|
|
32
|
+
pnpm add use-scroll-animate
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick Start (Vanilla JS / HTML)
|
|
36
|
+
|
|
37
|
+
The easiest way to use it is via HTML `data-sa` attributes.
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<!-- 1. Add data-sa attributes to your elements -->
|
|
41
|
+
<div data-sa data-sa-animation="fade-in-up" data-sa-duration="800">
|
|
42
|
+
I will animate when scrolled into view!
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<div data-sa data-sa-animation="zoom-in" data-sa-delay="200">
|
|
46
|
+
Me too, with a delay!
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<script type="module">
|
|
50
|
+
// 2. Import and initialize
|
|
51
|
+
import ScrollAnimate from 'use-scroll-animate';
|
|
52
|
+
|
|
53
|
+
ScrollAnimate.init();
|
|
54
|
+
</script>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## React Integration
|
|
58
|
+
|
|
59
|
+
We provide a dedicated hook for React users.
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
import { createReactHooks } from 'use-scroll-animate/react';
|
|
63
|
+
import React from 'react';
|
|
64
|
+
|
|
65
|
+
const { useScrollAnimate, useScrollStagger } = createReactHooks(React);
|
|
66
|
+
|
|
67
|
+
function App() {
|
|
68
|
+
// Single element animation
|
|
69
|
+
const titleRef = useScrollAnimate({ animation: 'fade-in-down', duration: 1000 });
|
|
70
|
+
|
|
71
|
+
// Staggered list animation
|
|
72
|
+
const listRef = useScrollStagger({ animation: 'fade-in-up', stagger: 100 });
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<main>
|
|
76
|
+
<h1 ref={titleRef}>Welcome to my site</h1>
|
|
77
|
+
|
|
78
|
+
<ul ref={listRef}>
|
|
79
|
+
<li>Item 1</li>
|
|
80
|
+
<li>Item 2</li>
|
|
81
|
+
<li>Item 3</li>
|
|
82
|
+
</ul>
|
|
83
|
+
</main>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Vue 3 Integration
|
|
89
|
+
|
|
90
|
+
First-class support for Vue 3 Composition API.
|
|
91
|
+
|
|
92
|
+
```vue
|
|
93
|
+
<template>
|
|
94
|
+
<main>
|
|
95
|
+
<h1 :ref="el => titleRef = el">Welcome to my site</h1>
|
|
96
|
+
</main>
|
|
97
|
+
</template>
|
|
98
|
+
|
|
99
|
+
<script setup>
|
|
100
|
+
import { ref, onMounted, onUnmounted } from 'vue';
|
|
101
|
+
import { createVueComposables } from 'use-scroll-animate/vue';
|
|
102
|
+
|
|
103
|
+
const { useScrollAnimate } = createVueComposables({ ref, onMounted, onUnmounted });
|
|
104
|
+
|
|
105
|
+
const { animateRef: titleRef } = useScrollAnimate({
|
|
106
|
+
animation: 'slide-right',
|
|
107
|
+
duration: 800
|
|
108
|
+
});
|
|
109
|
+
</script>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Built-in Animations
|
|
113
|
+
|
|
114
|
+
Choose from 19 highly optimized built-in presets:
|
|
115
|
+
|
|
116
|
+
- `fade-in`, `fade-in-up`, `fade-in-down`, `fade-in-left`, `fade-in-right`
|
|
117
|
+
- `zoom-in`, `zoom-out`
|
|
118
|
+
- `slide-up`, `slide-down`, `slide-left`, `slide-right`
|
|
119
|
+
- `flip-x`, `flip-y`
|
|
120
|
+
- `bounce`, `rotate-in`, `blur-in`
|
|
121
|
+
- `skew-in`, `scale-x`, `scale-y`
|
|
122
|
+
|
|
123
|
+
## Configuration Options
|
|
124
|
+
|
|
125
|
+
You can pass these options via JavaScript or as `data-sa-*` attributes in HTML.
|
|
126
|
+
|
|
127
|
+
| Option | Type | Default | Description |
|
|
128
|
+
|--------|------|---------|-------------|
|
|
129
|
+
| `animation` | `string` \| `string[]` \| `object` | `['fade-in-up']` | Preset name, array of presets, or custom keyframes |
|
|
130
|
+
| `duration` | `number` | `600` | Animation duration in ms |
|
|
131
|
+
| `delay` | `number` | `0` | Delay before animation starts in ms |
|
|
132
|
+
| `easing` | `string` | `ease` | CSS easing function (`linear`, `ease-out`, `spring`, etc.) |
|
|
133
|
+
| `threshold` | `number` \| `number[]` | `0.1` | Intersection threshold (0 to 1) or array for progress |
|
|
134
|
+
| `rootMargin` | `string` | `0px` | Root margin for IntersectionObserver |
|
|
135
|
+
| `repeat` | `boolean` | `false` | Replay animation every time it enters viewport |
|
|
136
|
+
| `stagger` | `number` | `0` | Delay between sibling elements in ms |
|
|
137
|
+
| `parallax` | `object` | `{}` | Parallax effect configuration (x, y, rotate, scale, speed) |
|
|
138
|
+
| `onProgress` | `(el, progress) => void` | `undefined` | Callback with scroll progress (0 to 1) |
|
|
139
|
+
|
|
140
|
+
## Advanced Usage
|
|
141
|
+
|
|
142
|
+
### Multiple Animations
|
|
143
|
+
|
|
144
|
+
Combine multiple built-in presets for richer effects. For example, `['fade-in-up', 'zoom-in']`.
|
|
145
|
+
|
|
146
|
+
```html
|
|
147
|
+
<div data-sa data-sa-animation="fade-in-up, zoom-in" data-sa-duration="1200">
|
|
148
|
+
I will fade in from bottom and zoom in!
|
|
149
|
+
</div>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Parallax Effect
|
|
153
|
+
|
|
154
|
+
Apply a parallax effect based on scroll position. Use `data-sa-parallax-x`, `data-sa-parallax-y`, `data-sa-parallax-rotate`, `data-sa-parallax-scale`.
|
|
155
|
+
|
|
156
|
+
```html
|
|
157
|
+
<div data-sa data-sa-parallax-y="-100px" data-sa-parallax-speed="0.5">
|
|
158
|
+
I will move up 100px as you scroll!
|
|
159
|
+
</div>
|
|
160
|
+
|
|
161
|
+
<div data-sa data-sa-parallax-rotate="30" data-sa-parallax-speed="0.8">
|
|
162
|
+
I will rotate 30 degrees as you scroll!
|
|
163
|
+
</div>
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Scroll Progress Listener
|
|
167
|
+
|
|
168
|
+
Get real-time scroll progress (0 to 1) for an element.
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
import ScrollAnimate from 'use-scroll-animate';
|
|
172
|
+
|
|
173
|
+
ScrollAnimate.observe('.progress-bar', {
|
|
174
|
+
onProgress: (el, progress) => {
|
|
175
|
+
(el as HTMLElement).style.width = `${progress * 100}%`;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Custom Animations
|
|
181
|
+
|
|
182
|
+
You can define your own animations using the Web Animations API keyframe format:
|
|
183
|
+
|
|
184
|
+
```javascript
|
|
185
|
+
import ScrollAnimate from 'use-scroll-animate';
|
|
186
|
+
|
|
187
|
+
ScrollAnimate.observe('.custom-box', {
|
|
188
|
+
animation: {
|
|
189
|
+
from: { opacity: 0, transform: 'scale(0.5) rotate(-45deg)' },
|
|
190
|
+
to: { opacity: 1, transform: 'scale(1) rotate(0deg)' }
|
|
191
|
+
},
|
|
192
|
+
duration: 1000,
|
|
193
|
+
easing: 'spring'
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Callbacks
|
|
198
|
+
|
|
199
|
+
```javascript
|
|
200
|
+
ScrollAnimate.observe('.track-me', {
|
|
201
|
+
onStart: (el) => console.log('Animation started on', el),
|
|
202
|
+
onComplete: (el) => console.log('Animation finished on', el),
|
|
203
|
+
onEnter: (el) => console.log('Element entered viewport'),
|
|
204
|
+
onLeave: (el) => console.log('Element left viewport')
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Contributing
|
|
209
|
+
|
|
210
|
+
Contributions are always welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/README_ja.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# use-scroll-animate 🚀
|
|
4
|
+
|
|
5
|
+
**軽量(~2.9KB gzipped)、依存関係なしのモダンWeb向けスクロールアニメーションライブラリ。**
|
|
6
|
+
|
|
7
|
+
[](https://github.com/HarrisonCN/use-scroll-animate/releases)
|
|
8
|
+
[](https://github.com/HarrisonCN/use-scroll-animate)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
|
|
11
|
+
[English](./README.md) | [简体中文](./README_zh.md)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
## なぜ `use-scroll-animate` なのか?
|
|
16
|
+
|
|
17
|
+
2025年、パフォーマンスはすべてです。従来のスクロールアニメーションライブラリは、重い依存関係をバンドルしたり、古いスクロールイベントリスナーに依存したり、特定のフレームワークを強制したりすることがよくあります。
|
|
18
|
+
|
|
19
|
+
`use-scroll-animate` は違います:
|
|
20
|
+
- ⚡ **依存関係なし**:純粋な Vanilla JS/TypeScript。
|
|
21
|
+
- 🚀 **高パフォーマンス**:`IntersectionObserver` とネイティブの `Web Animations API` で駆動。スクロールイベントリスナーなし、レイアウトスラッシングなし。
|
|
22
|
+
- 🪶 **超軽量**:Gzip後わずか約2.9KB。
|
|
23
|
+
- 🧩 **フレームワークに依存しない**:Vanilla JS、React、Vue、Svelteなどとシームレスに動作。一流の React Hooks と Vue Composables を内蔵。
|
|
24
|
+
- ♿ **アクセシブル**:`prefers-reduced-motion` を標準でサポート。
|
|
25
|
+
|
|
26
|
+
## インストール
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install use-scroll-animate
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## クイックスタート (Vanilla JS / HTML)
|
|
33
|
+
|
|
34
|
+
最も簡単な方法は、HTML の `data-sa` 属性を使用することです。
|
|
35
|
+
|
|
36
|
+
```html
|
|
37
|
+
<!-- 1. 要素に data-sa 属性を追加 -->
|
|
38
|
+
<div data-sa data-sa-animation="fade-in-up" data-sa-duration="800">
|
|
39
|
+
スクロールされるとアニメーションします!
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<script type="module">
|
|
43
|
+
// 2. インポートして初期化
|
|
44
|
+
import ScrollAnimate from 'use-scroll-animate';
|
|
45
|
+
ScrollAnimate.init();
|
|
46
|
+
</script>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## v1.2.0 の新機能
|
|
50
|
+
|
|
51
|
+
- **一度だけ実行 (Once)**:アニメーション実行後に監視を自動停止し、リソースを節約。
|
|
52
|
+
- **オフセット (Offset)**:要素がビューポートに入ってから何ピクセル後にアニメーションを開始するかを指定可能。
|
|
53
|
+
- **新しいプリセット**:`shimmer`(シマー)、`pulse`(パルス)、`swing`(スイング)を追加。
|
|
54
|
+
- **多言語サポート**:中国語と日本語のドキュメントを追加。
|
|
55
|
+
|
|
56
|
+
## 主な設定
|
|
57
|
+
|
|
58
|
+
| オプション | 型 | デフォルト | 説明 |
|
|
59
|
+
|--------|------|---------|-------------|
|
|
60
|
+
| `animation` | `string` \| `string[]` | `'fade-in-up'` | プリセット名またはプリセットの配列 |
|
|
61
|
+
| `duration` | `number` | `600` | アニメーションの長さ (ms) |
|
|
62
|
+
| `delay` | `number` | `0` | アニメーションの遅延 (ms) |
|
|
63
|
+
| `once` | `boolean` | `true` | 一度だけ実行するかどうか |
|
|
64
|
+
| `offset` | `number` | `0` | アニメーションを開始するビューポートのオフセット (px) |
|
|
65
|
+
| `parallax` | `object` | `{}` | パララックス効果の設定 |
|
|
66
|
+
|
|
67
|
+
## ライセンス
|
|
68
|
+
|
|
69
|
+
このプロジェクトは MIT ライセンスの下でライセンスされています - 詳細は [LICENSE](LICENSE) ファイルを参照してください。
|
package/README_zh.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# use-scroll-animate 🚀
|
|
4
|
+
|
|
5
|
+
**一个轻量级(~2.9KB gzipped)、零依赖的现代 Web 滚动动画库。**
|
|
6
|
+
|
|
7
|
+
[](https://github.com/HarrisonCN/use-scroll-animate/releases)
|
|
8
|
+
[](https://github.com/HarrisonCN/use-scroll-animate)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
|
|
11
|
+
[English](./README.md) | [日本語](./README_ja.md)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
## 为什么选择 `use-scroll-animate`?
|
|
16
|
+
|
|
17
|
+
在 2025 年,性能至关重要。传统的滚动动画库通常捆绑了沉重的依赖,依赖过时的滚动事件监听器,或者强制你使用特定的框架。
|
|
18
|
+
|
|
19
|
+
`use-scroll-animate` 的设计初衷截然不同:
|
|
20
|
+
- ⚡ **零依赖**:纯原生 JS/TypeScript 编写。
|
|
21
|
+
- 🚀 **高性能**:由 `IntersectionObserver` 和原生 `Web Animations API` 驱动。无滚动事件监听,无布局抖动。
|
|
22
|
+
- 🪶 **极轻量**:Gzip 后仅约 2.9KB。
|
|
23
|
+
- 🧩 **框架无关**:完美支持原生 JS、React、Vue、Svelte 等。内置一流的 React Hooks 和 Vue Composables。
|
|
24
|
+
- ♿ **无障碍**:原生支持 `prefers-reduced-motion`。
|
|
25
|
+
|
|
26
|
+
## 安装
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install use-scroll-animate
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 快速上手 (原生 JS / HTML)
|
|
33
|
+
|
|
34
|
+
最简单的方法是通过 HTML 的 `data-sa` 属性。
|
|
35
|
+
|
|
36
|
+
```html
|
|
37
|
+
<!-- 1. 为元素添加 data-sa 属性 -->
|
|
38
|
+
<div data-sa data-sa-animation="fade-in-up" data-sa-duration="800">
|
|
39
|
+
当滚动到我时,我会动起来!
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<script type="module">
|
|
43
|
+
// 2. 导入并初始化
|
|
44
|
+
import ScrollAnimate from 'use-scroll-animate';
|
|
45
|
+
ScrollAnimate.init();
|
|
46
|
+
</script>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## v1.2.0 新特性
|
|
50
|
+
|
|
51
|
+
- **单次触发 (Once)**:动画触发后自动停止观察,节省资源。
|
|
52
|
+
- **视口偏移 (Offset)**:支持设置元素进入视口多少像素后才触发动画。
|
|
53
|
+
- **新预设**:新增 `shimmer`(流光)、`pulse`(脉冲)、`swing`(摇摆)。
|
|
54
|
+
- **多语言支持**:新增中文和日文文档。
|
|
55
|
+
|
|
56
|
+
## 核心配置
|
|
57
|
+
|
|
58
|
+
| 选项 | 类型 | 默认值 | 描述 |
|
|
59
|
+
|--------|------|---------|-------------|
|
|
60
|
+
| `animation` | `string` \| `string[]` | `'fade-in-up'` | 预设名称或预设数组 |
|
|
61
|
+
| `duration` | `number` | `600` | 动画持续时间 (ms) |
|
|
62
|
+
| `delay` | `number` | `0` | 动画延迟 (ms) |
|
|
63
|
+
| `once` | `boolean` | `true` | 是否只触发一次 |
|
|
64
|
+
| `offset` | `number` | `0` | 触发动画的视口偏移量 (px) |
|
|
65
|
+
| `parallax` | `object` | `{}` | 视差效果配置 |
|
|
66
|
+
|
|
67
|
+
## 许可证
|
|
68
|
+
|
|
69
|
+
本项目采用 MIT 许可证 - 详情请参阅 [LICENSE](LICENSE) 文件。
|