Answer the question
In order to leave comments, you need to log in
How to make a horizontal menu with a swipe?
Hello!
Please tell me, are there any ready-made solutions for a horizontal menu with a slope (more precisely, a swipe)?
It is necessary that if the menu does not fit into the width of the parent container, then the menu items do not go to the second row, but hide and the menu can be scrolled horizontally
. x: scroll - not suitable(
Answer the question
In order to leave comments, you need to log in
Use swiper. Everything is in the doc and examples. Including for such a situation
Just solved the same problem. Wrote a class that is responsible for horizontal scrolling.
The essence is simple - we listen to mousedown on the block, mousemove on the document, then we set the scrollLeft to the block depending on the mouse movement.
Any block will have overflow-x: auto, you just need to additionally set for this block
::-webkit-scrollbar
display: none
<div class="container">
<div class="menu">
<div class="menu-element">Меню</div>
<div class="menu-element">Еще чето</div>
<div class="menu-element">И еще</div>
</div>
</div>
.container {
width: 100%;
overflow-x: auto;
}
.container::-webkit-scrollbar { // честно, уже не помню как это правильно написать на чистом css
display: none
}
.menu {
display: flex
flex-wrap: none // запрещаем переносить элементы при переполнении блока
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question