@alpinejs/docs 3.14.1-revision.1 → 3.14.1-revision.2
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/package.json
CHANGED
package/src/en/plugins/anchor.md
CHANGED
package/src/en/plugins/focus.md
CHANGED
package/src/en/plugins/morph.md
CHANGED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
order: 3
|
|
3
|
+
title: Resize
|
|
4
|
+
description: An Alpine convenience wrapper for the Resize Observer API that allows you to easily react when an element is resized.
|
|
5
|
+
graph_image: https://alpinejs.dev/social_resize.jpg
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Resize Plugin
|
|
9
|
+
|
|
10
|
+
Alpine's Resize plugin is a convenience wrapper for the [Resize Observer](https://developer.mozilla.org/en-US/docs/Web/API/Resize_Observer_API) that allows you to easily react when an element changes size.
|
|
11
|
+
|
|
12
|
+
This is useful for: custom size-based animations, intelligent sticky positioning, conditionally adding attributes based on the element's size, etc.
|
|
13
|
+
|
|
14
|
+
<a name="installation"></a>
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
You can use this plugin by either including it from a `<script>` tag or installing it via NPM:
|
|
18
|
+
|
|
19
|
+
### Via CDN
|
|
20
|
+
|
|
21
|
+
You can include the CDN build of this plugin as a `<script>` tag, just make sure to include it BEFORE Alpine's core JS file.
|
|
22
|
+
|
|
23
|
+
```alpine
|
|
24
|
+
<!-- Alpine Plugins -->
|
|
25
|
+
<script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/resize@3.x.x/dist/cdn.min.js"></script>
|
|
26
|
+
|
|
27
|
+
<!-- Alpine Core -->
|
|
28
|
+
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Via NPM
|
|
32
|
+
|
|
33
|
+
You can install Resize from NPM for use inside your bundle like so:
|
|
34
|
+
|
|
35
|
+
```shell
|
|
36
|
+
npm install @alpinejs/resize
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Then initialize it from your bundle:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import Alpine from 'alpinejs'
|
|
43
|
+
import resize from '@alpinejs/resize'
|
|
44
|
+
|
|
45
|
+
Alpine.plugin(resize)
|
|
46
|
+
|
|
47
|
+
...
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
<a name="x-resize"></a>
|
|
51
|
+
## x-resize
|
|
52
|
+
|
|
53
|
+
The primary API for using this plugin is `x-resize`. You can add `x-resize` to any element within an Alpine component, and when that element is resized for any reason, the provided expression will execute with two magic properties: `$width` and `$height`.
|
|
54
|
+
|
|
55
|
+
For example, here's a simple example of using `x-resize` do display the width and height of an element as it changes size.
|
|
56
|
+
|
|
57
|
+
```alpine
|
|
58
|
+
<div
|
|
59
|
+
x-data="{ width: 0, height: 0 }"
|
|
60
|
+
x-resize="width = $width; height = $height"
|
|
61
|
+
>
|
|
62
|
+
<p x-text="'Width: ' + width + 'px'"></p>
|
|
63
|
+
<p x-text="'Height: ' + height + 'px'"></p>
|
|
64
|
+
</div>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
<!-- START_VERBATIM -->
|
|
68
|
+
<div class="demo">
|
|
69
|
+
<div x-data="{ width: 0, height: 0 }" x-resize="width = $width; height = $height">
|
|
70
|
+
<i>Resize your browser window to see the width and height values change.</i>
|
|
71
|
+
<br><br>
|
|
72
|
+
<p x-text="'Width: ' + width + 'px'"></p>
|
|
73
|
+
<p x-text="'Height: ' + height + 'px'"></p>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
<!-- END_VERBATIM -->
|
|
77
|
+
|
|
78
|
+
<a name="modifiers"></a>
|
|
79
|
+
## Modifiers
|
|
80
|
+
|
|
81
|
+
<a name="document"></a>
|
|
82
|
+
### .document
|
|
83
|
+
|
|
84
|
+
It's often useful to observer the entire document's size, rather than a specific element. To do this, you can add the `.document` modifier to `x-resize`:
|
|
85
|
+
|
|
86
|
+
```alpine
|
|
87
|
+
<div x-resize.document="...">
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
<!-- START_VERBATIM -->
|
|
91
|
+
<div class="demo">
|
|
92
|
+
<div x-data="{ width: 0, height: 0 }" x-resize.document="width = $width; height = $height">
|
|
93
|
+
<i>Resize your browser window to see the document width and height values change.</i>
|
|
94
|
+
<br><br>
|
|
95
|
+
<p x-text="'Width: ' + width + 'px'"></p>
|
|
96
|
+
<p x-text="'Height: ' + height + 'px'"></p>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
<!-- END_VERBATIM -->
|
package/src/en/plugins/sort.md
CHANGED