简体   繁体   English

停在水平滚动页面上的某个点

[英]Stop at a certain point on a horizontal scrolling page

I am trying to accomplish a carousel type of functionality with forms. 我正在尝试使用表单完成轮播类型的功能。

I use an ng-repeat to loop through each set of form values to be displayed on each form field. 我使用ng-repeat遍历要在每个表单字段上显示的每组表单值。

The width of horizontal scrollable area: 水平滚动区域的宽度:

width of form * amount of forms 

图像示例

Currently I am able to scroll horizontally but ideally I would like to be able to scroll and stop at each form and take into account the index of the current form displayed. 目前,我能够水平滚动,但是理想情况下,我希望能够滚动和停止每个表格,并考虑当前显示的表格的索引。

Is there a way to detect that when scrolling, if there is an existing div, stop and display the form rather than freely scrolling? 有没有一种方法可以检测滚动时是否存在div,请停止并显示该窗体,而不是自由滚动? Or possibly a better way of handling this? 或者可能是更好的方式来处理此问题?

The CSS Scroll Snapping property is exactly what you are looking for. CSS Scroll Snapping属性正是您要寻找的。 the only issue is that it does not work consistently across browsers. 唯一的问题是,它不能在所有浏览器中一致地工作。 Here is how it works. 下面是它的工作原理。

HTML 的HTML

<div class='container'>
  <section class='child'></section>
  <section class='child'></section>
  <section class='child'></section>
</div>

CSS 的CSS

.container {
  scroll-snap-type: y mandatory;
}

.child {
  scroll-snap-align: start;
}

There are all types of options on how to use it. 有关如何使用它的所有类型的选项。 For more information take a look at this awesome article. 有关更多信息,请看这篇很棒的文章。 https://css-tricks.com/practical-css-scroll-snapping/ https://css-tricks.com/practical-css-scroll-snapping/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM