11# vue-overlay
22
3- To mask out the background when a dialog / modal or similar is opened, a overlay is needed.
3+ > To mask out the background when a dialog / modal or similar is opened, a overlay is needed.
44
55### [ Demo] ( https://vue-comps.github.io/vue-overlay )
66
7+ ### Features
8+ - singleton & z-index management to allow stacking
9+ - background doesn't move when scroll gets disabled
10+
711### Used in
812- [ side-nav] ( https://vue-comps.github.io/vue-side-nav )
913- [ modal] ( https://vue-comps.github.io/vue-comps-modal )
@@ -17,31 +21,44 @@ or include `build/bundle.js`.
1721
1822## Usage
1923``` coffee
20- # overlay is a singleton and is designed
21- # to be used in different places simultaniously
2224overlay = require (" vue-overlay" )(Vue)
2325# or, when using bundle.js
2426overlay = window .vueComps .overlay
27+ ```
28+ For examples see [ ` dev/ ` ] ( dev/ ) .
29+ If you need to reliable get the ` Vue ` instance, see [ vue-mixins/vue] ( https://github.com/paulpflug/vue-mixins#vue )
30+
31+ {zIndex, close} = overlay.open(options)
32+ ---
33+ - ` zIndex ` - the z-index of the opened overlay - will be raised by 5 for each overlay
34+ - ` close(callHooks=true) ` - shortcut for ` overlay.close(options,callHooks) ` - options will be the same instance used for opening
35+ - ` Options `
36+
37+ | Name | type | default | description |
38+ | ---:| --- | ---| --- |
39+ | opacity | Number | 0.5 | opacity of the overlay |
40+ | dismissable | Boolean | true | is the overlay dismissable by click or ESC? |
41+ | onBeforeOpen | Function | null | hook before open animation |
42+ | onOpened | Function | null | hook after open animation |
43+ | onBeforeClose | Function | null | hook before close animation |
44+ | onClosed | Function | null | hook after close animation |
45+ | allowScroll | Boolean | false | don't set ` overflow:hidden ` on body |
46+ | color | String | "black" | background-color of the overlay |
47+
48+ overlay.close(options=lastOverlay, callHooks=true)
49+ ---
50+ - ` options ` the options object which was used to open a overlay
51+ - ` callHooks ` set to ` false ` to suppress the calls of ` onBeforeClose ` and ` onClosed ` of that overlay
2552
26- # returns the z-index of the overlay + 1 (starts with 1001)
27- # and a function to close this specific overlay
28- {zIndex ,close } = overlay .open (options)
29- overlay .open () # z-index will raise by 5
30-
31- # close hooks of the first options object will be called
32- # and z-index will be lowered by 5
33- overlay .close ()
34- overlay .close () # overlay really closes
35-
36- # To close a specific overlay you can use
37- overlay .close (options) # where options must be the same object which is used to open
38- # or use the result from open
39- {close } = overlay .open ()
40- close ()
41-
42- # the overlay comes without animation, but you can easily set them up,
43- # for example with velocity.js:
44- Velocity = require (" velocity-animate" )
53+ overlay.fade({el,opacity,cb})
54+ ---
55+ overwrite to add a animation
56+ - ` el ` the ` div ` element of the overlay
57+ - ` opacity ` the target opacity of the opening/closing
58+ - ` cb ` a function which must be called when finished
59+
60+ example:
61+ ``` coffee
4562overlay .fade = ({el,opacity,cb}) ->
4663 Velocity el, {opacity : opacity},
4764 {
@@ -52,17 +69,9 @@ overlay.fade = ({el,opacity,cb}) ->
5269 }
5370```
5471
55- For examples see [ ` dev/ ` ] ( dev/ ) .
56- #### Options
57- | Name | type | default | description |
58- | ---:| --- | ---| --- |
59- | opacity | Number | 0.5 | opacity of the overlay |
60- | dissmissible | Boolean | true | is the overlay dissmissible by click or ESC? |
61- | onBeforeOpen | Function | null | hook before open animation |
62- | onOpened | Function | null | hook after open animation |
63- | onBeforeClose | Function | null | hook before close animation |
64- | onClosed | Function | null | hook after close animation |
65- | allowScroll | Boolean | false | don't set ` overflow:hidden ` on body |
72+
73+
74+
6675
6776# Development
6877Clone repository
0 commit comments