A
A
Alexander Osadchy2020-03-06 15:54:40
Apple Developer Program
Alexander Osadchy, 2020-03-06 15:54:40

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)?

6Qs3S.png

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

3 answer(s)
I
Ivan Vorobei, 2019-07-24
@ivanvorobei

Do nothing. Try from another account . Well or so

A
Alexey, 2020-03-06
@AleksRap

Use swiper. Everything is in the doc and examples. Including for such a situation

A
Andrew, 2020-03-06
@AndrewRusinas

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

On mobile, it will work just with these css properties, but on desktop, you will have to get confused with listening to events. Taking a third-party library for sliders is complete nonsense. You can write your solution here much easier and concisely.
UPD: I'll add some details.
At the html level it would be something like this:
<div class="container">

  <div class="menu">
     <div class="menu-element">Меню</div>
     <div class="menu-element">Еще чето</div>
     <div class="menu-element">И еще</div>
  </div>

</div>

CSS:
.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 question

Ask a Question

731 491 924 answers to any question