Skip to content

Commit 8543f83

Browse files
committed
feat: support scroll-triggered group animations with stagger
### Added - `data-triggle-scroll` now supports scroll-triggered group animations using IntersectionObserver - `data-triggle-stagger` now works with scroll-triggered groups - Support for separate scroll observer element triggering group animation ### Improved - Staggered group animation now triggers even if group items are in view - Modular scroll logic for improved maintainability ### Fixed - Bug where only first 1–2 elements in a staggered group would animate ### Compatibility - Fully backward compatible with all existing triggers
1 parent 4ea0558 commit 8543f83

File tree

8 files changed

+1573
-811
lines changed

8 files changed

+1573
-811
lines changed

CHANGELOG.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
# Changelog
22

3-
## 1.1.0 - 2025-07-07
3+
## v1.2.0 - 2025-07-07
4+
5+
### Added
6+
7+
- `data-triggle-scroll` now supports scroll-triggered group animations using `IntersectionObserver`
8+
- `data-triggle-stagger` now works with scroll-triggered groups
9+
- Added support for placing scroll observers separately from animated targets
10+
11+
### Improved
12+
13+
- Group scroll animation now works even if group items are already in the viewport
14+
- Better modularity of scroll-triggered logic for staggered groups
15+
16+
### Fixed
17+
18+
- Only first 1–2 elements animating when scroll-stagger was used — now resolved by isolating trigger element
19+
20+
### Compatibility
21+
22+
- Fully backward compatible with click, hover, chained, and keydown triggers
23+
24+
## v1.1.0 - 2025-07-07
425

526
### Added
627

@@ -23,7 +44,7 @@
2344

2445
- Fully backward compatible with previous `data-triggle`, `data-triggle-class`, and key/mouse event handling
2546

26-
## 1.0.3 - 2025-06-30
47+
## v1.0.3 - 2025-06-30
2748

2849
### Added
2950

@@ -38,7 +59,7 @@
3859

3960
- If using manual reinitialization, update your code to `triggle.init()` instead of `caTrigger.init()`
4061

41-
## 1.0.2 - 2025-06-30
62+
## v1.0.2 - 2025-06-30
4263

4364
### Added
4465

README.md

Lines changed: 113 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 🖱️ Trigger-based Animation Control — Triggle.js
1+
# Trigger-based Animation Control — **`triggle.js`**
22

33
![Vanilla JS](https://img.shields.io/badge/JS-Vanilla%20JS-brightgreen?style=for-the-badge)
44
![No Dependencies](https://img.shields.io/badge/Dependencies-None-lightgrey?style=for-the-badge)
@@ -11,7 +11,7 @@
1111
[![unpkg](https://img.shields.io/badge/CDN-unpkg-blue?style=for-the-badge)](https://unpkg.com/browse/triggle/)
1212
[![View Demo](https://img.shields.io/badge/🎬%20Live-Demo-green?style=for-the-badge)](https://yesiamrocks.github.io/Triggle/)
1313

14-
Enable trigger-based animations using simple `data-triggle` attributes. This plugin works seamlessly with `cssanimation.css` classes and lets you apply them on user interactions. It supports mouse, keyboard, touch, and custom event triggers — with optional animation control via delay, duration, reset, and key filters.
14+
Enable trigger-based animations using simple `data-triggle` attributes. This library works seamlessly with [`cssanimation.css`](https://github.com/yesiamrocks/cssanimation) classes and lets you apply them on user interactions. It supports mouse, keyboard, touch, and custom event triggers — with optional animation control via delay, duration, reset, and key filters.
1515

1616
## Features
1717

@@ -30,7 +30,7 @@ Enable trigger-based animations using simple `data-triggle` attributes. This plu
3030

3131
## Try It Live
3232

33-
Explore all supported triggers and features in the interactive playground: 👉 [Live Demo](https://yesiamrocks.github.io/Triggle/)
33+
Explore all supported triggers and features in the interactive playground: 👉 [Live Demo](https://yesiamrocks.github.io/triggle/)
3434

3535
## Installation
3636

@@ -48,7 +48,7 @@ npm install triggle
4848

4949
## Animations via cssanimation.io
5050

51-
Triggle.js works perfectly with the animation classes from **[cssanimation](https://github.com/yesiamrocks/cssanimation)** Install them:
51+
`triggle.js` works perfectly with the animation classes from **[cssanimation](https://github.com/yesiamrocks/cssanimation)** Install them:
5252

5353
```bash
5454
npm install @hellouxpavel/cssanimation
@@ -109,21 +109,23 @@ You can animate elements using the following trigger types via `data-triggle`:
109109
110110
## Attributes Reference
111111

112-
| Attribute | Type | Description |
113-
| -------------------------- | ------------ | -------------------------------------------------------------- |
114-
| `data-triggle` | `string` | Comma-separated events (e.g. `click,mouseenter`) |
115-
| `data-triggle-class` | `string` | Space-separated CSS classes to animate |
116-
| `data-triggle-reset` | `true/false` | Removes animation class after it finishes |
117-
| `data-triggle-delay` | `string` | CSS `animation-delay` (e.g., `0.5s`) |
118-
| `data-triggle-duration` | `string` | CSS `animation-duration` (e.g., `1s`) |
119-
| `data-triggle-toggle` | `true/false` | Toggles class on and off (instead of just adding) |
120-
| `data-triggle-once` | `true/false` | Triggers animation only once |
121-
| `data-triggle-target` | `string` | CSS selector for the element to animate (defaults to self) |
122-
| `data-triggle-key` | `string` | Keyboard filter (e.g. `enter`, `ctrl+s`, `a*`) |
123-
| `data-triggle-next` | `string` | CSS selector of element to animate **after this one finishes** |
124-
| `data-triggle-chain-delay` | `number` | Delay (in ms) before triggering `data-triggle-next` |
125-
| `data-triggle-group` | `string` | Group name to animate multiple elements together |
126-
| `data-triggle-stagger` | `number` | Delay (in ms) between each group's element animation |
112+
| Attribute | Type | Description |
113+
| -------------------------- | ------------ | ------------------------------------------------------------------ |
114+
| `data-triggle` | `string` | Comma-separated events (e.g. `click,mouseenter`) |
115+
| `data-triggle-class` | `string` | Space-separated CSS classes to animate |
116+
| `data-triggle-reset` | `true/false` | Removes animation class after it finishes |
117+
| `data-triggle-delay` | `string` | CSS `animation-delay` (e.g., `0.5s`) |
118+
| `data-triggle-duration` | `string` | CSS `animation-duration` (e.g., `1s`) |
119+
| `data-triggle-toggle` | `true/false` | Toggles class on and off (instead of just adding) |
120+
| `data-triggle-once` | `true/false` | Triggers animation only once |
121+
| `data-triggle-target` | `string` | CSS selector for the element to animate (defaults to self) |
122+
| `data-triggle-key` | `string` | Keyboard filter (e.g. `enter`, `ctrl+s`, `a*`) |
123+
| `data-triggle-next` | `string` | CSS selector of element to animate **after this one finishes** |
124+
| `data-triggle-chain-delay` | `number` | Delay (in ms) before triggering `data-triggle-next` |
125+
| `data-triggle-group` | `string` | Group name to animate multiple elements together |
126+
| `data-triggle-stagger` | `number` | Delay (in ms) between each group's element animation |
127+
| `data-triggle-scroll` | `true/false` | Use IntersectionObserver to animate when element scrolls into view |
128+
| `data-triggle-chain-loop` | `true` | Enables infinite looping between chained elements |
127129

128130
## Hover with Delay and Reset
129131

@@ -172,6 +174,67 @@ Automatically remove the animation class after it completes:
172174
</div>
173175
```
174176

177+
## Scroll Animation Example
178+
179+
```html
180+
<div
181+
data-triggle="scroll"
182+
data-triggle-scroll="true"
183+
data-triggle-class="fadeInUp"
184+
data-triggle-reset="true"
185+
data-triggle-once="true">
186+
I animate when visible
187+
</div>
188+
```
189+
190+
- Triggers `fadeInUp` once when 50% of the element is in view.
191+
- Combine with `data-triggle-once="true"` to prevent re-animation.
192+
193+
## Scroll-Based Staggered Animation
194+
195+
Trigger Element:
196+
197+
```html
198+
<div
199+
data-triggle="scroll"
200+
data-triggle-scroll="true"
201+
data-triggle-group="feature"
202+
data-triggle-class="fadeIn"
203+
data-triggle-stagger="300"
204+
data-triggle-once="true"></div>
205+
```
206+
207+
Staggered/Grouped Targets:
208+
209+
```html
210+
<div
211+
data-triggle-class="fadeIn"
212+
data-triggle-reset="true"
213+
data-triggle-group="feature">
214+
Card A
215+
</div>
216+
217+
<div
218+
data-triggle-class="fadeIn"
219+
data-triggle-reset="true"
220+
data-triggle-group="feature">
221+
Card B
222+
</div>
223+
224+
<div
225+
data-triggle-class="fadeIn"
226+
data-triggle-reset="true"
227+
data-triggle-group="feature">
228+
Card C
229+
</div>
230+
```
231+
232+
Behavior:
233+
234+
- When the **trigger element** scrolls into view, all elements in the `feature` group animate.
235+
- Each card will stagger with a `300ms` delay between them.
236+
- Add `data-triggle-once="true"` to prevent repeated scroll triggers.
237+
175238
## Chained Animation Example
176239

177240
```html
@@ -193,6 +256,28 @@ When the button is clicked:
193256
2. Once that finishes, #step2 animates with slideInUp
194257
3. `#step2` will animate 500ms after `zoomIn` ends on the button.
195258

259+
## Chain Loop Example (data-triggle-chain-loop)
260+
261+
```html
262+
<div
263+
id="box1"
264+
data-triggle="click"
265+
data-triggle-class="fadeIn"
266+
data-triggle-next="#box2"
267+
data-triggle-chain-delay="500"
268+
data-triggle-chain-loop="true">
269+
Start Loop
270+
</div>
271+
272+
<div
273+
id="box2"
274+
data-triggle-class="fadeOut"
275+
data-triggle-next="#box1"
276+
data-triggle-chain-delay="500"></div>
277+
```
278+
279+
- This will loop between `box1` and `box2` indefinitely.
280+
196281
## Group Triggering Example
197282

198283
```html
@@ -314,14 +399,6 @@ window.triggle.destroy(); // Removes all listeners
314399
window.triggle.init(); // Re-initializes all triggers
315400
```
316401

317-
### Supported Passive Events
318-
319-
The following triggers use passive listeners for optimal performance:
320-
321-
- `touchstart`
322-
- `touchend`
323-
- `scroll`
324-
325402
## Global Disable (Optional)
326403

327404
To disable all animations globally (e.g., for accessibility/testing), set:
@@ -344,6 +421,14 @@ window.__trg_DEBUG = true;
344421
window.__trg_TRIGGER_DISABLED = true;
345422
```
346423

424+
## Supported Passive Events
425+
426+
The following triggers use passive listeners for optimal performance:
427+
428+
- `touchstart`
429+
- `touchend`
430+
- `scroll`
431+
347432
## Performance Notes
348433

349434
To improve responsiveness on mobile devices, `triggle.js` uses **passive event listeners** for scroll-blocking events like `touchstart`, `touchend`, and `scroll`. This eliminates warnings in modern browsers (e.g., Chrome) and improves interaction smoothness.
@@ -353,7 +438,7 @@ To improve responsiveness on mobile devices, `triggle.js` uses **passive event l
353438
- Core class `.cssanimation` class is required (from [cssanimation](https://github.com/yesiamrocks/cssanimation)).
354439
- Use `data-triggle-*` attributes only on the intended element — avoid duplication on deeply nested structures to prevent conflicts.
355440

356-
## Plugin Architecture Summary
441+
## Library Architecture Summary
357442

358443
- Lightweight, zero-dependency vanilla JS
359444
- Fast event listener setup using DOMContentLoaded

0 commit comments

Comments
 (0)