gpt4 book ai didi

javascript - 如何防止或禁用 Bootstrap 4 弹出窗口自动定位行为(自调整行为)

转载 作者:行者123 更新时间:2023-11-30 14:02:37 25 4
gpt4 key购买 nike

我在我的元素中使用 Bootstrap 4 框架,并使用弹出框来满足我的要求。当我使用弹出窗口时,我注意到当视口(viewport)从纵向更改为横向时,弹出窗口本身会自动调整位置。

弹出窗口具有固定高度,我已将数据放置设置为底部。从纵向切换到横向时,它会自动调整位置并更改为顶部位置。

我的要求是我需要将弹出窗口放置在所有屏幕和视口(viewport)的底部,并希望防止其从底部到顶部位置的 self 调整行为。

当我调查这个问题时,我发现高度超过了视口(viewport)高度,因此导致了这个问题。

任何帮助或解决方案将不胜感激。提前致谢。 :)

Link : `https://jsbin.com/paladipepi/1/edit?html,css,js,output`

重现步骤:

1)打开链接https://jsbin.com/paladipepi/1/edit?html,css,js,output,在Chrome浏览器中输出输出

2) 打开模拟器并选择任何移动设备 (iPhone6/iPhoneX) 并单击弹出框。

3) 切换到横向模式

预期结果:应该放在底部

实际结果:自动调整到顶部。

代码

$(function () {
$('[data-toggle="popover"]').popover({
trigger: 'focus'
})
})
.subheader{
position:sticky;
}

.popover-body{
height:340px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

</head>
<body>
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
</header>
<div class="subheader">

<nav class="nav nav-pills nav-fill">
<a class="nav-item nav-link active" href="#" data-container="body" data-toggle="popover" data-placement="bottom" data-content="Vivamus
sagittis lacus vel augue laoreet rutrum faucibus.">Active</a>
<a class="nav-item nav-link" href="#" data-container="body" data-toggle="popover" data-placement="bottom" data-content="Vivamus
sagittis lacus vel augue laoreet rutrum faucibus.">Popver 1</a>
<a class="nav-item nav-link" href="#" data-container="body" data-toggle="popover" data-placement="bottom" data-content="Vivamus
sagittis lacus vel augue laoreet rutrum faucibus.">Popver 2</a>
<a class="nav-item nav-link disabled" href="#" tabindex="-1" aria-disabled="true" data-container="body" data-toggle="popover" data-placement="bottom" data-content="Vivamus
sagittis lacus vel augue laoreet rutrum faucibus.">Popver 3</a>
</nav>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>


</html>

最佳答案

万岁!!!!!!!!!!!!!!!!!!!!!!!!!!!

得到解决方案

在 Bootstrap Popover 选项中将 fallbackPlacement 设置为 ['left', 'right', 'top', 'bottom']

Link: https://popper.js.org/popper-documentation.html#modifiers..flip.behavior

<script>
$(function() {
$('[data-toggle="popover"]').popover({
container: '.subheader',
fallbackPlacement : ['left', 'right', 'top', 'bottom']
})
})
</script>

关于javascript - 如何防止或禁用 Bootstrap 4 弹出窗口自动定位行为(自调整行为),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56054401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com