Bootstrap JS Popover

JS Popover

The Popover component is similar to tooltips; it is a pop-up box that appears when the user clicks on an element. The difference is that the popover can contain much more content.

Enable via data-* Attributes

The data-toggle="popover" activates the popover.
The title attribute specifies the header text of the popover.
The data-content attribute specifies the text that should be displayed inside the popover's body.

Example

<a href="#" data-toggle="popover" title="Popover Header" data-content="Some content inside the popover">Toggle popover</a>
Try it Yourself »

Via JavaScript

Popovers are not CSS-only plugins, and must therefore be initialized with jQuery: select the specified element and call the popover() method.

Example

// Select all elements with data-toggle="popover" in the document$('[data-toggle="popover"]').popover(); 

// Select a specified element$('#myPopover').popover();
Try it Yourself »

Popover Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-placement="".
NameTypeDefaultDescriptionTry it
animationbooleantrue
Specifies whether to add a CSS fade transition effect when opening and closing the popover
  • true - Add a fading effect
  • false - Do not add a fading effect
Try it
containerstring, or the boolean falsefalseAppends the popover to a specific element.
Example: container: 'body'
Try it
contentstring""Specifies the text inside the popover's bodyTry it
delaynumber, or object0Specifies the number of milliseconds it will take to open and close the popover.

To specify a delay for opening and another one for closing, use the object structure:

delay: {show: 500, hide: 100} - which will take 500 ms to open the popover, but only 100 ms to close it
Try it
htmlboolean falseSpecifies whether to accept HTML tags in the popover:

  • true - Accept HTML tags
  • false - Do not accept HTML tags
Note: The HTML must be inserted in the title attribute (or using the title option).

When set to false (default), jQuery's text() method will be used. Use this if you are worried about XSS attacks
Try it
placementstring"right"Specifies the popover position. Possible values:

  • "top" - Popover on top
  • "bottom" - Popover on bottom
  • "left" - Popover on left
  • "right" - Popover on right
  • "auto" - Lets the browser decide the position of the popover. For example, if the value is "auto left", the popover will display on the left side when possible, otherwise on the right. If the value is "auto bottom", the popover will display at the bottom when possible, otherwise on the top
Try it
selectorstring, or the boolean falsefalseAdds the popover to a specified selectorTry it
templatestringBase HTML to use when creating the popover.

The popover's title will be injected into the .popover-header.

The popover's content will be injected into the .popover-body.

.arrow will become the popover's arrow.

The outermost wrapper element should have the .popover class.
titlestring""Specifies the header text of the popoverTry it
triggerstring"click"Specifies how the popover is triggered. Possible values:

  • "click" - Trigger the popover with a click
  • "hover" - Trigger the popover on hover
  • "focus" - Trigger the popover when it gets focus (by tabbing or clicking .e.g)
  • "manual" - Trigger the popover manually
Tip: To pass multiple values, separate them with a space
Try it
offsetnumber or a string0Offset of the popover relative to its target
fallbackPlacementstring or an aray"flip"Specifies which position Popper wil use on fallback
boundarystring or element"scrollParent"Overflow constraint boundary of the popover. Accepts the values "viewport", "window" or "scrollParent", or an HTML element

Popover Methods

The following table lists all available popover methods.
MethodDescriptionTry it
.popover(options)Activates the popover with an option. See options above for valid valuesTry it
.popover("show")Shows the popoverTry it
.popover("hide")Hides the popoverTry it
.popover("toggle")Toggles the popoverTry it
.popover("dispose")Hides and destroys the popoverTry it
.popover("enable")Enables the popover the ability to be shown. This is default
.popover("disable")Removes the ability to show a popover. The popover can only be shown if it is re-enabled again
.popover("toggleEnabled")Toggles the ability for the popover to be shown or hidden
.popover("update")Updates the position of the popover

Popover Events

The following table lists all available popover events.

EventDescriptionTry it
show.bs.popoverOccurs when the popover is about to be shownTry it
shown.bs.popoverOccurs when the popover is fully shown (after CSS transitions have completed)Try it
hide.bs.popoverOccurs when the popover is about to be hiddenTry it
hidden.bs.popoverOccurs when the popover is fully hidden (after CSS transitions have completed)Try it
inserted.bs.popoverOccurs after the show.bs.popover event when the popover template has been added to the DOM


Credit: www.w3schools.com
Bootstrap JS Popover Bootstrap JS Popover Reviewed by webmission on 11:08 Rating: 5

No comments:

Powered by Blogger.