I would like the popover to always stick on the same position and doesn't change when scrolling: https://jsfiddle.net/eloyrubio/aq9Laaew/251011/
var options = {
placement: 'top',
title: 'I should be on top',
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque lobortis nisl et metus varius lobortis. Sed sit amet posuere velit. Curabitur vel blandit mauris, a rutrum ante. Praesent sit amet orci viverra arcu sodales posuere.',
html: false
};
$('#po1').popover(options).popover('show');
I am using Bootstrap 4.1.3 and I saw that Popover extends Tooltip: https://github.com/twbs/bootstrap/blob/v4-dev/js/src/popover.js#L70
And here is the Tooltip code: https://github.com/twbs/bootstrap/blob/v4-dev/js/src/tooltip.js
You should add another option of fallbackPlacement
:
var options = {
placement: 'top',
fallbackPlacement: ['top'],
flip: 'top',
title: 'I should be on top',
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque lobortis nisl et metus varius lobortis. Sed sit amet posuere velit. Curabitur vel blandit mauris, a rutrum ante. Praesent sit amet orci viverra arcu sodales posuere.',
html: false
};
It passes that value to flip.behavior
(see more).
See working example: https://jsfiddle.net/aq9Laaew/251047/