You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| `gutterSize` | Number | `10` | Gutter size in pixels. |
87
+
| `snapOffset` | Number | `30` | Snap to minimum size offset in pixels. |
88
+
| `direction` | String | `'horizontal'` | Direction to split: horizontal or vertical. |
89
+
| `cursor` | String | `'col-resize'` | Cursor to display while dragging. |
89
90
| `gutter` | Function | | Called to create each gutter element |
90
91
| `elementStyle` | Function | | Called to set the style of each element. |
91
92
| `gutterStyle` | Function | | Called to set the style of the gutter. |
@@ -106,17 +107,17 @@ __THIS IS THE #1 QUESTION ABOUT THE LIBRARY__.
106
107
107
108
#### sizes
108
109
109
-
An array of initial sizes of the elements, specified as percentage values. Example: Setting the initial sizes to 25% and 75%.
110
+
An array of initial sizes of the elements, specified as percentage values. Example: Setting the initial sizes to `25%` and `75%`.
110
111
111
112
```js
112
113
Split(['#one', '#two'], {
113
114
sizes: [25, 75]
114
115
})
115
116
```
116
117
117
-
#### minSize. Default: 100
118
+
#### minSize. Default: `100`
118
119
119
-
An array of minimum sizes of the elements, specified as pixel values. Example: Setting the minimum sizes to 100px and 300px, respectively.
120
+
An array of minimum sizes of the elements, specified as pixel values. Example: Setting the minimum sizes to `100px` and `300px`, respectively.
120
121
121
122
```js
122
123
Split(['#one', '#two'], {
@@ -132,39 +133,53 @@ Split(['#one', '#two'], {
132
133
})
133
134
```
134
135
135
-
#### gutterSize. Default: 10
136
+
#### expandToMin. Default: `false`
136
137
137
-
Gutter size in pixels. Example: Setting the gutter size to 20px.
138
+
When the split is created, if `expandToMin` is `true`, the minSize for each element overrides the percentage value from the `sizes` option.
139
+
Example: The first element (`#one`) is set to 25% width of the parent container. However, it's `minSize` is `300px`. Using `expandToMin:true` means that
140
+
the first element will always load at at least `300px`, even if `25%` were smaller.
141
+
142
+
```js
143
+
Split(['#one', '#two'], {
144
+
sizes: [25, 75],
145
+
minSize: [300, 100],
146
+
expanedToMin:true,
147
+
})
148
+
```
149
+
150
+
#### gutterSize. Default: `10`
151
+
152
+
Gutter size in pixels. Example: Setting the gutter size to `20px`.
138
153
139
154
```js
140
155
Split(['#one', '#two'], {
141
156
gutterSize:20
142
157
})
143
158
```
144
159
145
-
#### snapOffset. Default: 30
160
+
#### snapOffset. Default: `30`
146
161
147
-
Snap to minimum size at this offset in pixels. Example: Set to 0 to disable to snap effect.
162
+
Snap to minimum size at this offset in pixels. Example: Set to `0` to disable to snap effect.
148
163
149
164
```js
150
165
Split(['#one', '#two'], {
151
166
snapOffset:0
152
167
})
153
168
```
154
169
155
-
#### direction. Default: 'horizontal'
170
+
#### direction. Default: `'horizontal'`
156
171
157
-
Direction to split in. Can be 'vertical' or 'horizontal'. Determines which CSS properties are applied (ie. width/height) to each element and gutter. Example: split vertically:
172
+
Direction to split in. Can be `'vertical'` or `'horizontal'`. Determines which CSS properties are applied (ie. width/height) to each element and gutter. Example: split vertically:
158
173
159
174
```js
160
175
Split(['#one', '#two'], {
161
176
direction:'vertical'
162
177
})
163
178
```
164
179
165
-
#### cursor. Default: 'col-resize'
180
+
#### cursor. Default: `'col-resize'`
166
181
167
-
Cursor to show on the gutter (also applied to the two adjacent elements when dragging to prevent flickering). Defaults to 'col-resize', so should be switched to 'row-resize' when using direction: 'vertical':
182
+
Cursor to show on the gutter (also applied to the two adjacent elements when dragging to prevent flickering). Defaults to `'col-resize'`, so should be switched to `'row-resize'` when using `direction:'vertical'`:
168
183
169
184
```js
170
185
Split(['#one', '#two'], {
@@ -178,7 +193,7 @@ Split(['#one', '#two'], {
178
193
Optional function called to create each gutter element. The signature looks like this:
179
194
180
195
```js
181
-
(index, direction) =>HTMLElement
196
+
(index, direction, pairElement) =>HTMLElement
182
197
```
183
198
184
199
Defaults to creating a `div` with `class="gutter gutter-horizontal"` or `class="gutter gutter-vertical"`, depending on the direction. The default gutter function looks like this:
@@ -193,6 +208,15 @@ Defaults to creating a `div` with `class="gutter gutter-horizontal"` or `class="
193
208
194
209
The returned element is then inserted into the DOM, and it's width or height are set. This option can be used to clone an existing DOM element, or to create a new element with custom styles.
195
210
211
+
Returning a falsey value like `null` or `false` will not insert a gutter. This behavior was added in v1.4.1.
212
+
An additional argument, `pairElement`, is passed to the gutter function: this is the DOM element after (to the right or below) the gutter. This argument was added in v1.4.1.
213
+
214
+
This final argument makes it easy to return the gutter that has already been created, for example, if `split.destroy()` was called with the option to preserve the gutters.
Optional function called setting the CSS style of the elements. The signature looks like this:
@@ -201,7 +225,7 @@ Optional function called setting the CSS style of the elements. The signature lo
201
225
(dimension, elementSize, gutterSize) =>Object
202
226
```
203
227
204
-
Dimension will be a string, 'width' or 'height', and can be used in the return style. elementSize is the target percentage value of the element, and gutterSize is the target pixel value of the gutter.
228
+
Dimension will be a string, `'width'` or `'height'`, and can be used in the return style. `elementSize` is the target percentage value of the element, and `gutterSize` is the target pixel value of the gutter.
205
229
206
230
It should return an object with CSS properties to apply to the element. For horizontal splits, the return object looks like this:
207
231
@@ -235,7 +259,7 @@ Optional function called when setting the CSS style of the gutters. The signatur
235
259
(dimension, gutterSize) =>Object
236
260
```
237
261
238
-
Dimension is a string, either 'width' or 'height', and gutterSize is a pixel value representing the width of the gutter.
262
+
Dimension is a string, either `'width'` or `'height'`, and `gutterSize` is a pixel value representing the width of the gutter.
239
263
240
264
It should return a similar object as `elementStyle`, an object with CSS properties to apply to the gutter. Since gutters have fixed widths, it will generally look like this:
241
265
@@ -245,12 +269,20 @@ It should return a similar object as `elementStyle`, an object with CSS properti
245
269
}
246
270
```
247
271
248
-
Both `elementStyle` and `gutterStyle` are called continously while dragging, so don't do anything besides return the style object in these functions.
272
+
Both `elementStyle` and `gutterStyle` are called continously while dragging, so don't do anything besides return the style object in these functions. Both of these functions should be *pure*, returning the same values for the same inputs and not modifying any external state.
249
273
250
274
#### onDrag, onDragStart, onDragEnd
251
275
252
276
Callbacks that can be added on drag (fired continously), drag start and drag end. If doing more than basic operations in `onDrag`, add a debounce function to rate limit the callback.
253
277
278
+
`onDragStart` and `onDragEnd` are passed the initial and final sizes of the split since it's a common pattern to access the sizes this way.
279
+
280
+
Their function signature looks like this, where `sizes` is an array of percentage values like returned by `getSizes()`:
281
+
282
+
```js
283
+
(sizes) => {}
284
+
```
285
+
254
286
## Usage Examples
255
287
256
288
Reference HTML for examples. Gutters are inserted automatically:
@@ -263,7 +295,7 @@ Reference HTML for examples. Gutters are inserted automatically:
263
295
</div>
264
296
```
265
297
266
-
A split with two elements, starting at 25% and 75% wide with 200px minimum width.
298
+
A split with two elements, starting at `25%` and `75%` wide, with `200px` minimum width.
267
299
268
300
```js
269
301
Split(['#one', '#two'], {
@@ -272,7 +304,7 @@ Split(['#one', '#two'], {
272
304
});
273
305
```
274
306
275
-
A split with three elements, starting with even widths with 100px, 100px and 300px minimum widths, respectively.
307
+
A split with three elements, starting with even (default) widths and minimum widths set to `100px`, `100px` and `300px`, respectively.
276
308
277
309
```js
278
310
Split(['#one', '#two', '#three'], {
@@ -288,16 +320,6 @@ Split(['#one', '#two'], {
288
320
});
289
321
```
290
322
291
-
Specifying the initial widths with CSS values. Not recommended, the size/gutter calculations would have to be done before hand and won't scale on viewport resize.
292
-
293
-
```js
294
-
Split(['#one', '#two'], {
295
-
sizes: ['200px', '500px']
296
-
});
297
-
```
298
-
299
-
JSFiddle style is also possible: [Demo](http://nathancahill.github.io/Split.js/examples/jsfiddle.html).
Flexbox layout is supported by customizing the `elementStyle` and `gutterStyle` CSS. Given a layout like this:
346
+
Flex layout is supported easily by adding a `display: flex` to the parent element. The `width` or `height` CSS values
347
+
assigned by default by Split.js work well with flex.
325
348
326
349
```html
327
350
<div id="flex">
@@ -339,7 +362,7 @@ And CSS style like this:
339
362
}
340
363
```
341
364
342
-
Then the `elementStyle` and `gutterStyle` can be used to set flex-basis:
365
+
For more complicated flex layouts, the `elementStyle` and `gutterStyle` can be used to set flex-basis:
343
366
344
367
```js
345
368
Split(['#flex-1', '#flex-2'], {
@@ -383,16 +406,17 @@ instance.getSizes()
383
406
384
407
#### .collapse(index)
385
408
386
-
collapse changes the size of element at `index` to 0. Every element except the last is collapsed towards the front (left or top). The last is collapsed towards the back. Not supported in IE8. Added in v1.1.0:
409
+
collapse changes the size of element at `index` to it's `minSize`. Every element except the last is collapsed towards the front (left or top). The last is collapsed towards the back. Not supported in IE8. Added in v1.1.0:
0 commit comments