User Interaction
To specify when the Popover should be shown and hidden, set the showEvent and hideEvent properties. These properties can accept several events at once as well as an object.
- $(function() {
- $("#popoverContainer").dxPopover({
- target: "#image",
- showEvent: 'dxhoverstart',
- hideEvent: 'dxhoverend'
- });
- });
- <img id="image" src="https://url/to/an/image" />
- <div id="popoverContainer">
- <p>Popover content</p>
- </div>
The Popover can also be hidden when a user clicks outside it. To control this behavior of the Popover, use the hideOnOutsideClick property.
- $(function() {
- $("#popoverContainer").dxPopover({
- target: "#image",
- showEvent: 'dxhoverstart',
- hideEvent: 'dxhoverend',
- hideOnOutsideClick: false
- });
- });
- <img id="image" src="https://url/to/an/image" />
- <div id="popoverContainer">
- <p>Popover content</p>
- </div>
API
To show or hide the Popover programmatically, call the show() or hide() method. The same thing can be done using the toggle(showing) method. Pass true or false to this method to show or hide the Popover, respectively.
- $(function() {
- $("#popoverContainer").dxPopover({
- target: "#image"
- });
- $("#showButton").dxButton({
- text: "Show the Popover",
- onClick: function () {
- $("#popoverContainer").dxPopover("show");
- // ===== or =====
- $("#popoverContainer").dxPopover("toggle", true);
- }
- });
- $("#hideButton").dxButton({
- text: "Hide the Popover",
- onClick: function () {
- $("#popoverContainer").dxPopover("hide");
- // ===== or =====
- $("#popoverContainer").dxPopover("toggle", false);
- }
- });
- });
- <img id="image" src="https://url/to/an/image" />
- <div id="popoverContainer">
- <p>Popover content</p>
- </div>
- <div id="showButton"></div>
- <div id="hideButton"></div>
The show() method called without arguments shows the Popover for the target specified beforehand. If you need to change the target once, call the show(target) method.
- $(function() {
- // ...
- $("#showButton").dxButton({
- text: "Show the Popover",
- onClick: function () {
- $("#popoverContainer").dxPopover("show", "#newTarget");
- }
- });
- });
Events
To execute certain commands before or after the Popover was shown/hidden, handle the showing, shown, hiding or hidden event. If the event handling function is not going to be changed during the lifetime of the UI component, assign it to the corresponding onEventName property when you configure the UI component.
- $(function () {
- $("#popoverContainer").dxPopover({
- // ...
- onShowing: function (e) {
- // Handler of the "showing" event
- },
- onShown: function (e) {
- // Handler of the "shown" event
- },
- onHiding: function (e) {
- // Handler of the "hiding" event
- },
- onHidden: function (e) {
- // Handler of the "hidden" event
- }
- });
- });
If you are going to change event handlers at runtime, or if you need to attach several handlers to a single event, subscribe to the events using the on(eventName, eventHandler) method.
- const hiddenEventHandler1 = function (e) {
- // First handler of the "hidden" event
- };
- const hiddenEventHandler2 = function (e) {
- // Second handler of the "hidden" event
- };
- $("#popoverContainer").dxPopover("instance")
- .on("hidden", hiddenEventHandler1)
- .on("hidden", hiddenEventHandler2);
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.