在 Bootstrap 4 Popover 中禁用翻转

Disable flip in Boostrap 4 Popover

我希望弹出窗口始终保持在同一位置并且在滚动时不会改变: 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');

image

我正在使用 Bootstrap 4.1.3,我看到 Popover 扩展了工具提示: https://github.com/twbs/bootstrap/blob/v4-dev/js/src/popover.js#L70

这是工具提示代码: https://github.com/twbs/bootstrap/blob/v4-dev/js/src/tooltip.js

您应该添加 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
};

它将那个值传递给 flip.behavior (see more)。

查看工作示例:https://jsfiddle.net/aq9Laaew/251047/