【发布时间】:2022-01-05 13:33:41
【问题描述】:
(编辑:原帖中的 JS 被错误收录 - 现在已删除)
我的水平滚动条工作得很好。
问题是我的幻灯片是垂直可滚动的(这很好,因为有很多内容)这意味着当我向下滚动到幻灯片 1 的底部,然后水平滚动到幻灯片 2 时,视口确实会捕捉到幻灯片 2 的左侧,但视口位于幻灯片的底部。我希望视口也能捕捉到幻灯片 2 的顶部。
我无法找到解决此问题的方法,并且似乎只有 start、end 和 center 作为 scroll-snap-align 的工作值,但这并不能解决我的问题。
有人知道解决这个问题的方法吗?
参见下面的代码n-p。
#slidesContainer {
height: auto;
width: auto;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
position: relative;
overflow: scroll;
scroll-snap-type: x mandatory;
-webkit-overflow-scrolling: touch;
}
#slides {
color: black;
width: 100%;
height: auto;
font-size: 100px;
position: static;
flex-grow: 0;
flex-shrink: 0;
scroll-snap-align: start;
scroll-snap-stop: always;
}
<div id="slidesContainer">
<div id="slides" style="background-color:blue;">Slide 1<br><br> Scroll down until there is no more text, then scroll right text text text text text text text text text text text text text </div>
<div id="slides" style="background-color:green;">Slide 2<br><br>This text is not visible unless you scroll back up - this is the problem.</div>
<div id="slides" style="background-color:yellow;">Slide 3<br><br></div>
</div>
非常感谢。
【问题讨论】:
-
在没有任何视觉效果的情况下很难理解你想说什么。你是否有一个视觉原型/线框/gif/屏幕截图来说明你想要完成什么以及你有什么结果?您也可以将您的 HTML/CSS/JS 代码放在 Runnable
Snippet中吗?你想让你的水平滚动是垂直滚动的吗? -
@maiakd 我重新创建了一个简单的代码 sn-p。如果您在幻灯片 1 上向下滚动直到没有更多文本,然后水平滚动,您将看不到标题“幻灯片 2”,除非您滚动到顶部。我正在寻找一种让这种情况自动发生的方法。
-
重复使用ID无效。不唯一的 ID 不会识别任何内容。改用类,这是更好的做法。
标签: javascript html css horizontal-scrolling