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
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?
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.
Add overflow: hidden; to hide both the horizontal and vertical scrollbar.
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.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With