html - Fancybox 导致分屏布局滚动位置重置为顶部
问题描述
我的布局有两个可滚动的列,其中包含使用 Fancybox 3 显示的文本和缩略图。当 Fancybox 覆盖打开时,列的滚动位置会重置到顶部,而不是停留在原来的位置。
这是代码,jsfiddle演示了这个问题。
<body>
<div class="ma-spa-outer-container">
<div>
Fixed header
</div>
<div class="ma-spa-inner-container">
<div class="ma-spa-outer-container border-right">
<div class="ma-spa-inner-container">
<div class="ma-spa-col">
<p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>Click image below to open fancybox</p>
<div class="col-lg-2 col-md-4 col-6">
<a href="https://source.unsplash.com/pWkk7iiCoDM/400x300" class="d-block mb-4 h-100" data-fancybox="gallery" data-caption="As I open, the columns scrolled back to the top!">
<img class="img-fluid img-thumbnail" src="https://source.unsplash.com/pWkk7iiCoDM/400x300" alt="">
</a>
</div>
</div>
</div>
</div>
<div id="two" class="ma-spa-outer-container border-right text-left">
<div class="ma-spa-inner-container">
<div class="ma-spa-inner-container">
<div class="ma-spa-col">
<p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>scroll down</p><p>Click image below to open fancybox</p>
<div class="col-lg-2 col-md-4 col-6">
<a href="https://source.unsplash.com/pWkk7iiCoDM/400x300" class="d-block mb-4 h-100" data-fancybox="gallery" data-caption="As I open, the columns scrolled back to the top!">
<img class="img-fluid img-thumbnail" src="https://source.unsplash.com/pWkk7iiCoDM/400x300" alt="">
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
html,
body {
height: 100%;
}
.ma-spa-outer-container {
display: flex;
flex-direction: column;
height: 100%;
width: 100%;
}
.ma-spa-inner-container {
display: flex;
overflow: hidden;
height: 100%;
width: 100%;
}
.ma-spa-col {
height: 100%;
width: 100%;
overflow-y: scroll;
}
我试过Fancybox的autoFocus和backFocus选项,没有效果。尝试删除可滚动列,获得预期的行为,Fancybox 覆盖关闭后滚动位置保持不变。如果我从这个 css 中删除“html”:
html,
body {
height: 100%;
}
然后我得到了正确的行为,但是这两列失去了它们的滚动条并且页面滚动作为一个整体破坏了我的目的。
解决方案
上面链接的答案对我不起作用(适用于 fancybox 2,fancybox 3 中不存在引用的行)
相反,我在 jquery.fancybox.css 中注释掉了这一行:
.fancybox-active {
//height: auto;
}
推荐阅读
- mysql - MySQL:从 5.5 升级到 5.7 后无法连接到 Sequel Pro 上的 MySql
- x11 - XTestFakeKeyEvent 调用被吞没
- java - 如何生成 JPA 元模型类?(2018 年 7 月)
- xamarin.forms - 如果从 Xamarin Forms 调用,AWS Lambda 函数不返回任何记录
- sql - SQL按带有条件的子字符串排序
- tfs - 如何在 VSTS 中更改项目的流程?
- php - JavaScript 和 CSS 未在 Azure PHP (Codeigniter) Web 应用程序中加载
- xamarin.forms - 如何在我的列表中保存日期后刷新列表视图
- html - 单独的按钮:活动与 parentDiv:活动
- c# - 根据计算的属性索引排序列表