CSS решение
Для простого перетаскиваемого меню Swiper не нужен ( Overkill ).Когда вы устанавливаете переполнение для прокрутки (или авто) - полоса прокрутки на мобильном телефоне выглядит великолепно.
.scroll {
white-space: nowrap;
overflow-x: auto;
}
Swiper горизонтальное направление прокрутки на основе слайдов (CSS селектор .swiper-container-vertical
).
Раствор Swiper
Использование слайдов (не один длинный слайд с overflow:auto
) ** Снова "перебор"
https://codepen.io/ezra_siton/pen/PoYVBqZ
var swiper = new Swiper(".swiper-container", {
slidesPerView: "auto",
freeMode: true,
slideToClickedSlide: true,
spaceBetween: 10,
scrollbar: {
el: ".swiper-scrollbar",
draggable: true,
dragSize: 100
},
mousewheel: true
});
html,
body {
position: relative;
height: 100%;
}
body {
background: #fff;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 34px;
color: #000;
margin: 0;
padding: 0;
}
.swiper-container {
width: 100%;
height: auto;
padding-bottom: 15px!important; /*space for the scrollbar*/
}
.swiper-slide {
width: auto!important; /*remove all important from your code*/
background-color: #333;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
border-radius: 30px;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* Change the link color to #111 (black) on hover */
li:hover {
background-color: #111;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.1/css/swiper.min.css" rel="stylesheet"/>
<br>
<div class="swiper-container" id="scroll-tags">
<ul class="swiper-wrapper">
<li class="swiper-slide"><a href="#">item 1</a></li>
<li class="swiper-slide"><a href="#">item 2</a></li>
<li class="swiper-slide"><a href="">item 3</a></li>
<li class="swiper-slide"><a href="#">item 4</a></li>
<li class="swiper-slide"><a href="#">item 5</a></li>
<li class="swiper-slide"><a href="#">item 6</a></li>
<li class="swiper-slide"><a href="#">item 7</a></li>
<li class="swiper-slide"><a href="#">item 8</a></li>
<li class="swiper-slide"><a href="#">item 9</a></li>
<li class="swiper-slide"><a href="#">item 10</a></li>
<li class="swiper-slide"><a href="#">item 11</a></li>
<li class="swiper-slide"><a href="#">item 12</a></li>
<li class="swiper-slide"><a href="#">item 13</a></li>
<li class="swiper-slide"><a href="#">item 14</a></li>
<li class="swiper-slide"><a href="#">item 15</a></li>
<li class="swiper-slide"><a href="#">item 16</a></li>
<li class="swiper-slide"><a href="#">item 17</a></li>
<li class="swiper-slide"><a href="#">item 18</a></li>
<li class="swiper-slide"><a href="#">item 19</a></li>
<li class="swiper-slide"><a href="#">item 20</a></li>
</ul>
<div class="swiper-scrollbar"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.1/js/swiper.min.js"></script>
Swiper "плохой" Один длинный слайд
Снова странно (мощность Swiper основана на слайдах) - но также будет работать
var swiper = new Swiper(".swiper-container", {
slidesPerView: "auto",
freeMode: true,
slideToClickedSlide: true,
spaceBetween: 20,
scrollbar: {
el: ".swiper-scrollbar",
draggable: true
},
mousewheel: true
});
//horizontal
html,
body {
position: relative;
height: 100%;
}
body {
background: #fff;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 34px;
color: #000;
margin: 0;
padding: 0;
}
.swiper-container {
width: 100%;
height: auto;
padding-bottom: 30px!important; /*space for the scrollbar*/
}
.swiper-slide {
width: auto!important;;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
a {
background-color: #333;
}
a {
color: white;
text-align: center;
padding: 10px 40px;
text-decoration: none;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.1/css/swiper.min.css" rel="stylesheet"/>
<br>
<div class="swiper-container" id="scroll-tags">
<ul class="swiper-wrapper">
<div class="swiper-slide">
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
<a href="#">Very long item</a>
</div>
</ul>
<div class="swiper-scrollbar"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.1/js/swiper.min.js"></script>