Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make bootstrap popover appear over a different element than its trigger

I'm trying to have a single "NEXT" button create different popovers (popover 1, 2, 3 etc...): Each popover should appear attached to a different div on the page.

We are trying to create a "Take a Tour" functionality where different features are explained by different popovers.

like image 849
Max Avatar asked Jun 17 '13 16:06

Max


People also ask

How do I show popover on hover?

Set the trigger option of the popover to hover instead of click , which is the default one. Or with an initialization option: $("#popover"). popover({ trigger: "hover" });

What is the difference between tooltip and popover?

A tooltip is used to embed a short note into a tag; by default they are activated by hovering over the tag. A popover is used to embed a longer note into a tag; by default they are activated by clicking on the tag.


1 Answers

Show/hide your popovers manually.

On the click of your 'Next' button, show and hide your popovers in sequence:

var currentPopover = -1;
var popovers = [];

// Initialize all the popovers to be "manually" displayed.
popovers.push($("#ctrl1").popover({ trigger: 'manual' }));
popovers.push($("#ctrl2").popover({ trigger: 'manual' }));
popovers.push($("#ctrl3").popover({ trigger: 'manual' }));

// On each button click, hide the currently displayed popover
// and show the next one.
$("#NextBtn").click(function() {
  if (currentPopover >= 0) {
    popovers[currentPopover].popover('hide');
  }

  currentPopover = currentPopover + 1;
  popovers[currentPopover].popover('show');
});

The above code has not been compiled or tested.

like image 160
Matt Houser Avatar answered Sep 25 '22 22:09

Matt Houser