Bootstrap with CSS
- Bootstrap - Responsive utilities
- Bootstrap - Helper Classes
- Bootstrap - Images
- Bootstrap - Buttons
- Bootstrap - Forms
- Bootstrap - Tables
- Bootstrap - Code
- Bootstrap - Typography
- Bootstrap - CSS Overview
- Bootstrap - Grid System
Bootstrap Layout Components
- Bootstrap - Wells
- Bootstrap - Panels
- Bootstrap - List Group
- Bootstrap - Media Object
- Bootstrap - Progress Bars
- Bootstrap - Alerts
- Bootstrap - Thumbnails
- Bootstrap - Page Header
- Bootstrap - Jumbotron
- Bootstrap - Badges
- Bootstrap - Labels
- Bootstrap - Pagination
- Bootstrap - Breadcrumb
- Bootstrap - Navbar
- Bootstrap - Navigation Elements
- Bootstrap - Input Groups
- Bootstrap - Button Dropdowns
- Bootstrap - Button Groups
- Bootstrap - Dropdowns
- Bootstrap - Glyphicons
Bootstrap Plugins
- Bootstrap - Affix Plugin
- Bootstrap - Carousel Plugin
- Bootstrap - Collapse Plugin
- Bootstrap - Button Plugin
- Bootstrap - Alert Plugin
- Bootstrap - Popover Plugin
- Bootstrap - Tooltip Plugin
- Bootstrap - Tab Plugin
- Bootstrap - Scrollspy Plugin
- Bootstrap - Dropdown Plugin
- Bootstrap - Modal Plugin
- Bootstrap - Transition Plugin
- Bootstrap - Plugins Overview
Bootstrap Demos
- Bootstrap - featured Demo
- Bootstrap - Icons Demo
- Bootstrap - Social Icons Demo
- Bootstrap - Calendar Demo
- Bootstrap - Map Demo
- Bootstrap - Caption Demo
- Bootstrap - Tabbed slider Demo
- Bootstrap - Ajax Demo
- Bootstrap - Admin Interface Demo
- Bootstrap - Alert Demo
- Bootstrap - Time line Demo
- Bootstrap - Slider Demo
- Bootstrap - Material Design Demo
- Bootstrap - Blog Demo
- Bootstrap - Navigation Demo
- Bootstrap - Responsive Demo
- Bootstrap - Images Demo
- Bootstrap - Buttons Demo
- Bootstrap - Form Demo
- Bootstrap - Table Demo
- Bootstrap - Grid Demo
Bootstrap Useful Resources
- Bootstrap - Discussion
- Bootstrap - Useful Resources
- Bootstrap - Quick Guide
- Bootstrap - Questions and Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Bootstrap - Popover Plugin
The popover is similar to tooltip, offering an extended view complete with a heading. For the popover to activate, a user just needs to hover the cursor over the element. The content of the popover can be populated entirely using the Bootstrap Data API. This method requires a tooltip.
If you want to include this plugin functionapty inspanidually, then you will need the popover.js and it has a dependency of the. Else, as mentioned in the chapter , you can include bootstrap.js or the minified bootstrap.min.js.
Usage
The popover plugin generates content and markup on demand, and by default places popover after their trigger element. You can add popover in the following two ways −
Via data attributes − To add a popover, add data-toggle = "popover" to an anchor/button tag. The title of the anchor will be the text of a popover. By default, popover is set to top by the plugin.
<a href = "#" data-toggle = "popover" title = "Example popover"> Hover over me </a>
Via JavaScript − Enable popovers via JavaScript using the following syntax −
$( #identifier ).popover(options)
Popover plugin is NOT only-css plugins pke dropdown or other plugins discussed in previous chapters. To use this plugin you MUST activate it using jquery (read javascript). To enable all the popovers on your page just use this script −
$(function () { $("[data-toggle = popover ]").popover(); });
Example
The following example demonstrates the use of popover plugin via data attributes.
<span class = "container" style = "padding: 100px 50px 10px;" > <button type = "button" class = "btn btn-default" title = "Popover title" data-container = "body" data-toggle = "popover" data-placement = "left" data-content = "Some content in Popover on left"> Popover on left </button> <button type = "button" class = "btn btn-primary" title = "Popover title" data-container = "body" data-toggle = "popover" data-placement = "top" data-content = "Some content in Popover on top"> Popover on top </button> <button type = "button" class = "btn btn-success" title = "Popover title" data-container = "body" data-toggle = "popover" data-placement = "bottom" data-content = "Some content in Popover on bottom"> Popover on bottom </button> <button type = "button" class = "btn btn-warning" title = "Popover title" data-container = "body" data-toggle = "popover" data-placement = "right" data-content = "Some content in Popover on right"> Popover on right </button> </span> <script> $(function (){ $("[data-toggle = popover ]").popover(); }); </script>
Options
There are certain options which can be added via the Bootstrap Data API or invoked via JavaScript. Following table psts the options −
Option Name | Type/Default Value | Data attribute name | Description |
---|---|---|---|
animation | boolean Default − true | data-animation | Apppes a CSS fade transition to the popover. |
html | boolean Default − false | data-html | Inserts HTML into the popover. If false, jQuery’s text method will be used to insert content into the dom. Use text if you’re worried about XSS attacks. |
placement | string|function Default − top | data-placement | Specifies how to position the popover (i.e., top|bottom|left|right|auto). When auto is specified, it will dynamically reorient the popover. For example, if placement is "auto left", the popover will display to the left when possible, otherwise it will display right. |
selector | string Default − false | data-selector | If a selector is provided, popover objects will be delegated to the specified targets. |
title | string | function Default − " | data-title | The title option is the default title value if the title attribute isn’t present. |
trigger | string Default − hover focus | data-trigger | Defines how the popover is triggered − cpck| hover | focus | manual. You may pass multiple triggers; separate them with a space. |
delay | number | object Default − 0 | data-delay | Delays showing and hiding the popover in ms — does not apply to manual trigger type. If a number is suppped, delay is appped to both hide/show. Object structure is − delay: { show: 500, hide: 100 } |
container | string | false Default − false | data-container | Appends the popover to a specific element. Example: container: body |
Methods
The following are some useful methods for popover −
Method | Description | Example |
---|---|---|
Options − .popover(options) |
Attaches a popover handler to an element collection. |
$().popover(options) |
Toggle − .popover( toggle ) |
Toggles an element s popover. |
$( #element ).popover( toggle ) |
Show − .popover( show ) |
Reveals an element s popover. |
$( #element ).popover( show ) |
Hide − .popover( hide ) |
Hides an element s popover. |
$( #element ).popover( hide ) |
Destroy − .popover( destroy ) |
Hides and destroys an element s popover. |
$( #element ).popover( destroy ) |
Example
The following example demonstrates the popover plugin methods −
<span class = "container" style = "padding: 100px 50px 10px;" > <button type = "button" class = "btn btn-default popover-show" title = "Popover title" data-container = "body" data-toggle = "popover" data-placement = "left" data-content = "Some content in Popover with show method"> Popover on left </button> <button type = "button" class = "btn btn-primary popover-hide" title = "Popover title" data-container = "body" data-toggle = "popover" data-placement = "top" data-content = "Some content in Popover-hide method"> Popover on top </button> <button type = "button" class = "btn btn-success popover-destroy" title = "Popover title" data-container = "body" data-toggle = "popover" data-placement = "bottom" data-content = "Some content in Popover-destroy method"> Popover on bottom </button> <button type = "button" class = "btn btn-warning popover-toggle" title = "Popover title" data-container = "body" data-toggle = "popover" data-placement = "top" data-content = "Some content in Popover-toggle method"> Popover on right </button> <br><br><br><br><br><br> <p class = "popover-options"> <a href = "#" type = "button" class = "btn btn-warning" title = "<h2>Title</h2>" data-container = "body" data-toggle = "popover" data-content = " <h4>Some content in Popover-options method</h4>"> Popover </a> </p> <script> $(function () { $( .popover-show ).popover( show );}); $(function () { $( .popover-hide ).popover( hide );}); $(function () { $( .popover-destroy ).popover( destroy );}); $(function () { $( .popover-toggle ).popover( toggle );}); $(function () { $(".popover-options a").popover({html : true });}); </script> </span>
Events
Following table psts the events to work with the popover plugin. This event may be used to hook into the function.
Event | Description | Example |
---|---|---|
show.bs.popover | This event fires immediately when the show instance method is called. |
$( #mypopover ).on( show.bs.popover , function () { // do something }) |
shown.bs.popover | This event is fired when the popover has been made visible to the user (will wait for CSS transitions to complete). |
$( #mypopover ).on( shown.bs.popover , function () { // do something }) |
hide.bs.popover | This event is fired immediately when the hide instance method has been called. |
$( #mypopover ).on( hide.bs.popover , function () { // do something }) |
hidden.bs.popover | This event is fired when the popover has finished being hidden from the user (will wait for CSS transitions to complete). |
$( #mypopover ).on( hidden.bs.popover , function () { // do something }) |
Example
The following example demonstrates the Popover plugin events −
<span clas = "container" style = "padding: 100px 50px 10px;" > <button type = "button" class = "btn btn-primary popover-show" title = "Popover title" data-container = "body" data-toggle = "popover" data-content = "Some content in Popover with show method"> Popover on left </button> </span> <script> $(function () { $( .popover-show ).popover( show );}); $(function () { $( .popover-show ).on( shown.bs.popover , function () { alert("Alert message on show"); })}); </script>Advertisements