【发布时间】:2019-10-14 18:59:39
【问题描述】:
前提条件
我正在尝试制作一个用户可以在其上滚动的数字列表选择器。
所选数字应该与容器的center 对齐。
一旦选择了一个数字,它应该被放大并改变颜色。
问题
- 如何将第一个或最新的项目捕捉到中心 容器?
- 是否有 CSS 或 JavaScript 方法来检测数字是
捕捉到中心然后在上面分配
selected类? - 不要依赖任何插件。
* {
box-sizing: border-box;
font-family: Roboto, sans-serif;
}
.container {
display: flex;
flex-direction: row;
width: 10rem;
height: 22rem;
border-radius: 3rem;
border: solid 0.2rem #b2b2c2;
background-color: #000000;
display: flex;
align-items: center;
justify-content: center;
}
.scrollport {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
width: 9.4rem;
height: 22rem;
overflow: auto;
scroll-snap-type: y mandatory;
}
.cell {
display: block;
scroll-snap-align: center;
flex-grow: 1;
flex-shrink: 0;
flex-basis: 33.3%;
display: flex;
justify-content: center;
align-items: center;
color: #e9e9f2;
font-size: 2.4rem;
}
.selected {
font-size: 3rem;
font-weight: bold;
color: #0073e6;
}
<div class="container">
<div class="scrollport">
<div class="cell">09</div>
<div class="cell selected">10</div>
<div class="cell">11</div>
<div class="cell">12</div>
<div class="cell">13</div>
<div class="cell">14</div>
<div class="cell">15</div>
<div class="cell">16</div>
</div>
</div>
预期结果
【问题讨论】:
-
我不清楚:您是否希望仅在滚动时选择您的号码,而无需单击它?如果是这样,您将如何选择列表中的第一项和最后一项?您还应该更改您的 sn-p IMO,因为在当前状态下,它准确显示了您的期望,因此人们可能会混淆要修复什么
-
感谢您的 cmets。给我几分钟。我会很快更新我的帖子。
-
这是两个问题。让我们坚持一个。
-
我对我的回答进行了编辑以回答您的两个问题
标签: javascript html css animation scroll