shopify-drag-carousel 1.0.2 → 1.0.4
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/README.md +71 -61
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,52 +18,84 @@ A tiny, zero-dependency behavior layer for smooth mouse and touch drag scrolling
|
|
|
18
18
|
npm install shopify-drag-carousel
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
```js
|
|
22
|
+
const DragCarousel = require("shopify-drag-carousel");
|
|
23
|
+
```
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
---
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
## Quick start (browser)
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
1. Add a horizontal row of children (your own layout: flex, grid, etc.).
|
|
30
|
+
2. Put the library on the page, then add class **`drag-carousel`** to the scroll container.
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
```html
|
|
33
|
+
<link
|
|
34
|
+
rel="stylesheet"
|
|
35
|
+
href="https://cdn.jsdelivr.net/npm/shopify-drag-carousel@1/style.css"
|
|
36
|
+
/>
|
|
37
|
+
<div class="drag-carousel">
|
|
38
|
+
<div>Slide A</div>
|
|
39
|
+
<div>Slide B</div>
|
|
40
|
+
<div>Slide C</div>
|
|
41
|
+
</div>
|
|
42
|
+
<script src="https://cdn.jsdelivr.net/npm/shopify-drag-carousel@1/index.js"></script>
|
|
43
|
+
```
|
|
32
44
|
|
|
33
|
-
|
|
45
|
+
After load, `window.DragCarousel` is available. Auto-init runs on `DOMContentLoaded` for every `.drag-carousel`.
|
|
34
46
|
|
|
35
|
-
|
|
47
|
+
**Manual init** (e.g. custom speed or arrows):
|
|
36
48
|
|
|
37
|
-
```
|
|
38
|
-
|
|
49
|
+
```html
|
|
50
|
+
<div id="strip"></div>
|
|
51
|
+
<button type="button" id="prev" aria-label="Previous">←</button>
|
|
52
|
+
<button type="button" id="next" aria-label="Next">→</button>
|
|
53
|
+
<script src="https://cdn.jsdelivr.net/npm/shopify-drag-carousel@1/index.js"></script>
|
|
54
|
+
<script>
|
|
55
|
+
new DragCarousel("#strip", {
|
|
56
|
+
speed: 1.5,
|
|
57
|
+
buttons: { prev: "#prev", next: "#next" },
|
|
58
|
+
});
|
|
59
|
+
</script>
|
|
39
60
|
```
|
|
40
61
|
|
|
41
|
-
|
|
62
|
+
Do **not** put `class="drag-carousel"` on the same node if you also call `new DragCarousel` on it with options (avoid double init).
|
|
42
63
|
|
|
43
|
-
|
|
64
|
+
---
|
|
44
65
|
|
|
45
|
-
## CDN
|
|
66
|
+
## CDN URLs
|
|
46
67
|
|
|
47
|
-
|
|
68
|
+
Use a **major** tag (`@1`) or pin an exact version (`@1.0.0`) in production.
|
|
48
69
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
70
|
+
| Asset | jsDelivr | unpkg |
|
|
71
|
+
| ----- | -------- | ----- |
|
|
72
|
+
| Script | [cdn.jsdelivr.net/npm/shopify-drag-carousel@1/index.js](https://cdn.jsdelivr.net/npm/shopify-drag-carousel@1/index.js) | [unpkg.com/shopify-drag-carousel@1/index.js](https://unpkg.com/shopify-drag-carousel@1/index.js) |
|
|
73
|
+
| Styles (optional) | [cdn.jsdelivr.net/npm/shopify-drag-carousel@1/style.css](https://cdn.jsdelivr.net/npm/shopify-drag-carousel@1/style.css) | [unpkg.com/shopify-drag-carousel@1/style.css](https://unpkg.com/shopify-drag-carousel@1/style.css) |
|
|
52
74
|
|
|
53
|
-
|
|
75
|
+
---
|
|
54
76
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
77
|
+
## Live example (bundled demo)
|
|
78
|
+
|
|
79
|
+
The package includes HTML examples under **`examples/`**:
|
|
80
|
+
|
|
81
|
+
| Demo | What it is |
|
|
82
|
+
| ---- | ----------- |
|
|
83
|
+
| **[examples/demo-cdn.html](https://unpkg.com/shopify-drag-carousel@1/examples/demo-cdn.html)** | Full page on **unpkg** — loads the library from the CDN, fetches sample products from [api.escuelajs.co](https://api.escuelajs.co/docs), drag + prev/next. Requires the version to exist on [npm](https://www.npmjs.com/package/shopify-drag-carousel). |
|
|
84
|
+
| **`examples/demo.html`** | Same UI with **relative** script paths — run a static server from the repo root (see below). |
|
|
85
|
+
|
|
86
|
+
**Run the local demo** (clone or `npm install shopify-drag-carousel`, then serve the **package root** over `http://`, not `file://`):
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npm run demo
|
|
60
90
|
```
|
|
61
91
|
|
|
62
|
-
|
|
92
|
+
Open [http://localhost:5173/examples/demo.html](http://localhost:5173/examples/demo.html) — or [http://localhost:5173/demo.html](http://localhost:5173/demo.html), which redirects to the example folder.
|
|
93
|
+
|
|
94
|
+
---
|
|
63
95
|
|
|
64
96
|
## Shopify (Liquid)
|
|
65
97
|
|
|
66
|
-
|
|
98
|
+
Load the script and optional CSS in your theme (e.g. `theme.liquid` or section assets).
|
|
67
99
|
|
|
68
100
|
```liquid
|
|
69
101
|
<div class="drag-carousel">
|
|
@@ -73,61 +105,39 @@ Drop the script (and optional stylesheet) in your theme—**theme.liquid** asset
|
|
|
73
105
|
</div>
|
|
74
106
|
```
|
|
75
107
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
After **dynamic** updates (e.g. section AJAX), call:
|
|
108
|
+
Style the row/cards yourself (flex, grid, etc.). After **dynamic** HTML (e.g. section AJAX), call:
|
|
79
109
|
|
|
80
110
|
```js
|
|
81
111
|
DragCarousel.initAll();
|
|
82
112
|
```
|
|
83
113
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
**Automatic:** Add class `drag-carousel` to your container; initialization runs when the DOM is ready.
|
|
87
|
-
|
|
88
|
-
**Manual:**
|
|
89
|
-
|
|
90
|
-
```js
|
|
91
|
-
const carousel = new DragCarousel('#my-row', {
|
|
92
|
-
speed: 1.5,
|
|
93
|
-
buttons: {
|
|
94
|
-
prev: '.prev-btn',
|
|
95
|
-
next: '.next-btn',
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
**Node / CommonJS:**
|
|
101
|
-
|
|
102
|
-
```js
|
|
103
|
-
const DragCarousel = require('shopify-drag-carousel');
|
|
104
|
-
new DragCarousel('.drag-carousel');
|
|
105
|
-
```
|
|
114
|
+
---
|
|
106
115
|
|
|
107
116
|
## API
|
|
108
117
|
|
|
109
118
|
### `new DragCarousel(selectorOrElement, options?)`
|
|
110
119
|
|
|
111
|
-
| Option
|
|
112
|
-
|
|
|
113
|
-
| `speed`
|
|
114
|
-
| `buttons` | `object` | `null`
|
|
120
|
+
| Option | Type | Default | Description |
|
|
121
|
+
| ------ | ---- | ------- | ----------- |
|
|
122
|
+
| `speed` | `number` | `1.5` | Multiplier for pointer movement vs. scroll |
|
|
123
|
+
| `buttons` | `object` | `null` | `{ prev: string, next: string }` — any valid `querySelector` string |
|
|
115
124
|
|
|
116
|
-
|
|
125
|
+
Selectors resolve with `document.querySelector` (first match).
|
|
117
126
|
|
|
118
127
|
### `DragCarousel.initAll()`
|
|
119
128
|
|
|
120
|
-
|
|
129
|
+
Initializes every `.drag-carousel` in the document that is not already initialized. Use after injecting new markup.
|
|
121
130
|
|
|
122
131
|
### `DragCarousel.isInitialized(element)`
|
|
123
132
|
|
|
124
|
-
Returns whether the
|
|
133
|
+
Returns whether the element already has carousel behavior.
|
|
134
|
+
|
|
135
|
+
---
|
|
125
136
|
|
|
126
137
|
## Constraints
|
|
127
138
|
|
|
128
|
-
- No React
|
|
129
|
-
-
|
|
130
|
-
- Intended to run directly in the browser via script tag or small bundles
|
|
139
|
+
- No React required; no bundler required for browser usage
|
|
140
|
+
- Intended for direct use via `<script>` or small bundles
|
|
131
141
|
|
|
132
142
|
## License
|
|
133
143
|
|
package/package.json
CHANGED