Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

The width of horizontal scrollable area:

width of form * amount of forms 

IMAGE EXAMPLE

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? Or possibly a better way of handling this?

like image 424
J.Do Avatar asked Jul 27 '18 13:07

J.Do


People also ask

How do I control horizontal scrolling?

To enable horizontal scrolling, we can use the CSS property overflow-x. If we assign the value scroll to the overflow-x property of the container element, the browser will hide horizontally overflowing content and make it accessible via horizontal scrolling.

How do I stop horizontal scrolling in web design?

Add overflow: hidden; to hide both the horizontal and vertical scrollbar.

Is horizontal scrolling bad for accessibility?

If yours only requires horizontal scrolling in one small area, then you should be fine. Intent: Having to scroll in two dimensions to view content on a page makes seeing and reading the content difficult.

How do I find out what is causing my horizontal scroll?

To find out which elements cause a horizontal scrollbar, you can use the devtools to delete elements one by one until the scrollbar disappears. When that happens, press ctrl/cmd Z to undo the delete, and drill down into the element to figure out which of the child elements cause the horizontal scrollbar.


1 Answers

The CSS Scroll Snapping property is exactly what you are looking for. the only issue is that it does not work consistently across browsers. Here is how it works.

HTML

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

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/

like image 101
David Genger Avatar answered Oct 21 '22 21:10

David Genger