@rethink-js/rt-slider 1.0.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/LICENSE +21 -0
- package/README.md +265 -0
- package/dist/index.js +1315 -0
- package/dist/index.js.map +7 -0
- package/dist/index.min.js +3 -0
- package/dist/index.min.js.map +7 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Rethink JS
|
|
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,265 @@
|
|
|
1
|
+
# rt-slider
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
[](https://www.npmjs.com/package/@rethink-js/rt-slider)
|
|
6
|
+
[](https://www.jsdelivr.com/package/npm/@rethink-js/rt-slider)
|
|
7
|
+
[](https://bundlephobia.com/package/@rethink-js/rt-slider)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
`rt-slider` is a lightweight JavaScript utility that creates touch-friendly sliders with smooth inertia scrolling and physics with:
|
|
11
|
+
|
|
12
|
+
- **Automatic dependency loading** (loads Lenis automatically)
|
|
13
|
+
- **Zero-config defaults** (works out of the box with basic selectors)
|
|
14
|
+
- Attribute-driven configuration
|
|
15
|
+
- Support for **multiple instances**
|
|
16
|
+
- A clean global API under `window.rtSlider`
|
|
17
|
+
- Defensive fallbacks to native scrolling on mobile
|
|
18
|
+
- Clear console logs for debugging and verification
|
|
19
|
+
|
|
20
|
+
**Primary dependency (GitHub):** <https://github.com/darkroomengineering/lenis>
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
# Table of Contents
|
|
25
|
+
|
|
26
|
+
- [1. Installation](#1-installation)
|
|
27
|
+
- [1.1 CDN (jsDelivr)](#11-cdn-jsdelivr)
|
|
28
|
+
- [1.2 npm](#12-npm)
|
|
29
|
+
- [2. Quick Start](#2-quick-start)
|
|
30
|
+
- [3. Activation Rules](#3-activation-rules)
|
|
31
|
+
- [4. Configuration (HTML Attributes)](#4-configuration-html-attributes)
|
|
32
|
+
- [5. Multiple Instances](#5-multiple-instances)
|
|
33
|
+
- [6. Global API](#6-global-api)
|
|
34
|
+
- [7. Console Logging](#7-console-logging)
|
|
35
|
+
- [8. Troubleshooting](#8-troubleshooting)
|
|
36
|
+
- [9. License](#9-license)
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 1. Installation
|
|
41
|
+
|
|
42
|
+
### 1.1 CDN (jsDelivr)
|
|
43
|
+
|
|
44
|
+
```html
|
|
45
|
+
<script src="[https://cdn.jsdelivr.net/npm/@rethink-js/rt-slider@latest/dist/index.min.js](https://cdn.jsdelivr.net/npm/@rethink-js/rt-slider@latest/dist/index.min.js)"></script>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 1.2 npm
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install @rethink-js/rt-slider
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Then bundle or load `dist/index.min.js` as appropriate for your build setup.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 2. Quick Start
|
|
60
|
+
|
|
61
|
+
Add the script to your page. To create a slider, add the `data-rt-slider` attribute to a container and specify the child selectors.
|
|
62
|
+
|
|
63
|
+
`rt-slider` will:
|
|
64
|
+
|
|
65
|
+
- Auto-initialize on DOM ready
|
|
66
|
+
- Load Lenis dynamically for desktop inertia
|
|
67
|
+
- Apply native touch scrolling styles for mobile
|
|
68
|
+
|
|
69
|
+
Example:
|
|
70
|
+
|
|
71
|
+
```html
|
|
72
|
+
<div data-rt-slider data-rt-list=".cms-list" data-rt-item=".cms-item">
|
|
73
|
+
<div class="cms-list">
|
|
74
|
+
<div class="cms-item">Slide 1</div>
|
|
75
|
+
<div class="cms-item">Slide 2</div>
|
|
76
|
+
<div class="cms-item">Slide 3</div>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
<script src="[https://cdn.jsdelivr.net/npm/@rethink-js/rt-slider@latest/dist/index.min.js](https://cdn.jsdelivr.net/npm/@rethink-js/rt-slider@latest/dist/index.min.js)"></script>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
> Note: If you do not provide `data-rt-list` and `data-rt-item`, the slider will not initialize.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 3. Activation Rules
|
|
88
|
+
|
|
89
|
+
The library activates when **any** of the following are true:
|
|
90
|
+
|
|
91
|
+
- An element with the attribute `data-rt-slider` is found in the DOM.
|
|
92
|
+
- The required `data-rt-list` and `data-rt-item` selectors resolve to valid elements within that container.
|
|
93
|
+
|
|
94
|
+
If these conditions are met, the library initializes the instance automatically.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 4. Configuration (HTML Attributes)
|
|
99
|
+
|
|
100
|
+
### Basic Setup
|
|
101
|
+
|
|
102
|
+
```html
|
|
103
|
+
<div data-rt-slider data-rt-list=".list-class" data-rt-item=".item-class">
|
|
104
|
+
...
|
|
105
|
+
</div>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### UI Controls (Optional)
|
|
109
|
+
|
|
110
|
+
```html
|
|
111
|
+
<div
|
|
112
|
+
data-rt-slider
|
|
113
|
+
data-rt-btn-prev=".prev-button"
|
|
114
|
+
data-rt-btn-next=".next-button"
|
|
115
|
+
data-rt-scroll-bar=".custom-scrollbar"
|
|
116
|
+
data-rt-scroll-track=".custom-track"
|
|
117
|
+
>
|
|
118
|
+
...
|
|
119
|
+
</div>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Core Attributes (Selectors)
|
|
123
|
+
|
|
124
|
+
| Attribute | Description | Required |
|
|
125
|
+
| ---------------------- | ----------------------------------------------- | -------- |
|
|
126
|
+
| `data-rt-slider` | Activates the slider instance | **Yes** |
|
|
127
|
+
| `data-rt-slider-id` | Optional identifier (auto-generated if missing) | No |
|
|
128
|
+
| `data-rt-list` | Selector for the scrollable wrapper | **Yes** |
|
|
129
|
+
| `data-rt-item` | Selector for individual slides | **Yes** |
|
|
130
|
+
| `data-rt-spacer` | Selector/Class for edge spacers (padding) | No |
|
|
131
|
+
| `data-rt-btn-prev` | Selector for "Previous" button | No |
|
|
132
|
+
| `data-rt-btn-next` | Selector for "Next" button | No |
|
|
133
|
+
| `data-rt-scroll-track` | Selector for custom scrollbar track | No |
|
|
134
|
+
| `data-rt-scroll-bar` | Selector for custom scrollbar thumb | No |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
### Physics & Behavior Configuration
|
|
139
|
+
|
|
140
|
+
These attributes control the Lenis instance used on desktop.
|
|
141
|
+
|
|
142
|
+
```html
|
|
143
|
+
<div
|
|
144
|
+
data-rt-slider
|
|
145
|
+
data-rt-slider-lerp="0.1"
|
|
146
|
+
data-rt-slider-infinite="false"
|
|
147
|
+
></div>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
| Attribute | Description | Default |
|
|
151
|
+
| ----------------------------- | -------------------------------------- | ------------- |
|
|
152
|
+
| `data-rt-slider-lerp` | Inertia interpolation (lower = slower) | `0.1` |
|
|
153
|
+
| `data-rt-slider-duration` | Scroll duration (alt to lerp) | `1.2` |
|
|
154
|
+
| `data-rt-slider-easing` | Easing function (e.g., `easeOutExpo`) | `easeOutQuad` |
|
|
155
|
+
| `data-rt-slider-orientation` | Scroll orientation | `horizontal` |
|
|
156
|
+
| `data-rt-slider-smooth-wheel` | Enable mouse wheel smoothing | `true` |
|
|
157
|
+
| `data-rt-slider-infinite` | Infinite scrolling | `false` |
|
|
158
|
+
| `data-rt-slider-auto-resize` | Recalculate on window resize | `true` |
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
### Advanced JSON Options
|
|
163
|
+
|
|
164
|
+
```html
|
|
165
|
+
<div
|
|
166
|
+
data-rt-slider
|
|
167
|
+
data-rt-slider-options-json='{"lerp":0.05, "wheelMultiplier": 2}'
|
|
168
|
+
></div>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Used to pass complex configuration objects directly to the underlying Lenis instance.
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
### Dependency Loader Overrides
|
|
176
|
+
|
|
177
|
+
The library automatically loads Lenis from a CDN if not present. You can rely on the default or load your own version before `rt-slider`.
|
|
178
|
+
|
|
179
|
+
| Attribute | Description |
|
|
180
|
+
| ---------------------- | --------------------------------------------------- |
|
|
181
|
+
| `data-rt-lenis="true"` | Add this to a script tag to identify external Lenis |
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## 5. Multiple Instances
|
|
186
|
+
|
|
187
|
+
`rt-slider` supports multiple independent instances on the same page.
|
|
188
|
+
|
|
189
|
+
Each instance:
|
|
190
|
+
|
|
191
|
+
- Has its own independent scroll physics.
|
|
192
|
+
- Calculates its own progress bars and button states.
|
|
193
|
+
- Is registered internally with a unique ID.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## 6. Global API
|
|
198
|
+
|
|
199
|
+
Once initialized:
|
|
200
|
+
|
|
201
|
+
```js
|
|
202
|
+
window.rtSlider;
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Common Methods
|
|
206
|
+
|
|
207
|
+
| Method | Description |
|
|
208
|
+
| -------------- | ------------------------------------------------ |
|
|
209
|
+
| `ids()` | Returns an array of active slider IDs |
|
|
210
|
+
| `get(id)` | Returns the slider instance object |
|
|
211
|
+
| `refresh()` | Forces a recalculation of layout (all instances) |
|
|
212
|
+
| `destroy(id?)` | Destroys specific instance or all if no ID given |
|
|
213
|
+
|
|
214
|
+
Example usage:
|
|
215
|
+
|
|
216
|
+
```js
|
|
217
|
+
// Refresh layout after an AJAX load
|
|
218
|
+
window.rtSlider.refresh();
|
|
219
|
+
|
|
220
|
+
// Destroy a specific slider
|
|
221
|
+
window.rtSlider.destroy("my-slider-id");
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## 7. Console Logging
|
|
227
|
+
|
|
228
|
+
`rt-slider` operates silently by default but provides warnings if:
|
|
229
|
+
|
|
230
|
+
- Required selectors (`data-rt-list`, `data-rt-item`) are missing.
|
|
231
|
+
- JSON configuration is invalid.
|
|
232
|
+
- Dependency loading fails.
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## 8. Troubleshooting
|
|
237
|
+
|
|
238
|
+
### Slider not initializing
|
|
239
|
+
|
|
240
|
+
- Ensure `data-rt-slider` is present on the parent.
|
|
241
|
+
- **Crucial:** Ensure `data-rt-list` and `data-rt-item` attributes match valid elements inside the container.
|
|
242
|
+
|
|
243
|
+
### Buttons not working
|
|
244
|
+
|
|
245
|
+
- Ensure the selectors in `data-rt-btn-prev` match your button elements.
|
|
246
|
+
- If buttons are outside the slider container, give them the attribute `data-rt-slider-for="slider-id"`.
|
|
247
|
+
|
|
248
|
+
### Scrollbar not moving
|
|
249
|
+
|
|
250
|
+
- Ensure `data-rt-scroll-track` and `data-rt-scroll-bar` are set correctly.
|
|
251
|
+
- The "bar" must be a child of the "track" in the DOM for standard styling, though the logic handles positioning.
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## 9. License
|
|
256
|
+
|
|
257
|
+
MIT License
|
|
258
|
+
|
|
259
|
+
Package: `@rethink-js/rt-slider` <br>
|
|
260
|
+
GitHub: [https://github.com/Rethink-JS/rt-slider](https://github.com/Rethink-JS/rt-slider)
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
by **Rethink JS** <br>
|
|
265
|
+
[https://github.com/Rethink-JS](https://github.com/Rethink-JS)
|