A component that displays a popover next to an element.
<script>
ons.ready(function() {
ons.createPopover('popover.html').then(function(popover) {
popover.show('#mybutton');
});
});
</script>
<script type="text/ons-template" id="popover.html">
<ons-popover cancelable>
<p style="text-align: center; opacity: 0.5;">This popover will choose which side it's displayed on automatically.</p>
</ons-popover>
</script>
See the Pen Alert, confirm and prompt dialogs by Onsen & Monaca (@onsen) on CodePen.
| Name | Type Default Value |
Description |
|---|---|---|
| var | String | Variable name to refer this popover. Optional |
| modifier | String | The appearance of the popover. Optional |
| direction | String | A space separated list of directions. If more than one direction is specified, it will be chosen automatically. Valid directions are "up", "down", "left" and "right". Optional |
| cancelable | If this attribute is set the popover can be closed by tapping the background or by pressing the back button. Optional | |
| disabled | If this attribute is set the popover is disabled. Optional | |
| animation | String | The animation used when showing an hiding the popover. Can be either "none" or "fade". Optional |
| mask-color | Color | Color of the background mask. Default is "rgba(0, 0, 0, 0.2)". Optional |
| ons-preshow | Expression | Allows you to specify custom behavior when the "preshow" event is fired. Optional |
| ons-prehide | Expression | Allows you to specify custom behavior when the "prehide" event is fired. Optional |
| ons-postshow | Expression | Allows you to specify custom behavior when the "postshow" event is fired. Optional |
| ons-posthide | Expression | Allows you to specify custom behavior when the "posthide" event is fired. Optional |
| ons-destroy | Expression | Allows you to specify custom behavior when the "destroy" event is fired. Optional |
| Modifier | Description |
|---|---|
| android | Display an Android style popover. |
| Signature | Description |
|---|---|
| show(target, [options]) | Open the popover and point it at a target. The target can be either an event, a css selector or a DOM element.. |
| hide([options]) | Close the popover. |
| isShown() | Returns whether the popover is visible or not. |
| destroy() | Destroy the popover and remove it from the DOM tree. |
| setCancelable(cancelable) | Set whether the popover can be canceled by the user when it is shown. |
| isCancelable() | Returns whether the popover is cancelable or not. |
| setDisabled(disabled) | Disable or enable the popover. |
| isDisabled() | Returns whether the popover is disabled or enabled. |
| on(eventName, listener) | Add an event listener. |
| once(eventName, listener) | Add an event listener that's only triggered once. |
| off(eventName, [listener]) | Remove an event listener. If the listener is not specified all listeners for the event type will be removed. |
| Name | Description |
|---|---|
| preshow | Fired just before the popover is displayed. |
| postshow | Fired just after the popover is displayed. |
| prehide | Fired just before the popover is hidden. |
| posthide | Fired just after the popover is hidden. |
Open the popover and point it at a target. The target can be either an event, a css selector or a DOM element..
| Name | Type | Description |
|---|---|---|
| target | String|Event|HTMLElement | Target element. Can be either a CSS selector, an event object or a DOM element. |
| options | Object | Parameter object. |
| options.animation | String | Animation name. Available animations are "fade" and "none". |
Close the popover.
| Name | Type | Description |
|---|---|---|
| options | Object | Parameter object. |
| options.animation | String | Animation name. Available animations are "fade" and "none". |
Returns whether the popover is visible or not.
Returns: true if the popover is visible.
Destroy the popover and remove it from the DOM tree.
Set whether the popover can be canceled by the user when it is shown.
| Name | Type | Description |
|---|---|---|
| cancelable | Boolean | If true the popover will be cancelable. |
Returns whether the popover is cancelable or not.
Returns: true if the popover is cancelable.
Disable or enable the popover.
| Name | Type | Description |
|---|---|---|
| disabled | Boolean | If true the popover will be disabled. |
Returns whether the popover is disabled or enabled.
Returns: true if the popover is disabled.
Add an event listener.
| Name | Type | Description |
|---|---|---|
| eventName | String | Name of the event. |
| listener | Function | Function to execute when the event is triggered. |
Add an event listener that's only triggered once.
| Name | Type | Description |
|---|---|---|
| eventName | String | Name of the event. |
| listener | Function | Function to execute when the event is triggered. |
Remove an event listener. If the listener is not specified all listeners for the event type will be removed.
| Name | Type | Description |
|---|---|---|
| eventName | String | Name of the event. |
| listener | Function | Function to execute when the event is triggered. |
Fired just before the popover is displayed.
| Name | Type | Description |
|---|---|---|
| event | Object | Event object. |
| event.popover | Object | Component object. |
| event.cancel | Function | Call this function to stop the popover from being shown. |
Fired just after the popover is displayed.
| Name | Type | Description |
|---|---|---|
| event | Object | Event object. |
| event.popover | Object | Component object. |
Fired just before the popover is hidden.
| Name | Type | Description |
|---|---|---|
| event | Object | Event object. |
| event.popover | Object | Component object. |
| event.cancel | Function | Call this function to stop the popover from being hidden. |
Fired just after the popover is hidden.
| Name | Type | Description |
|---|---|---|
| event | Object | Event object. |
| event.popover | Object | Component object. |