简体   繁体   English

Swiper slider,如何减小滚动条的宽度

[英]Swiper slider, how to reduce the width of the scrollbar

JavaScript JavaScript

 const projectsSwiper = new Swiper(".projects__swiper-start", {
       speed: 1000,
    
             slidesPerView: 3,
    
             navigation: {
                nextEl: ".projects__swiper-next",
                prevEl: ".projects__swiper-prev",
             },
       watchOverFlow: true,
       simulateTouch: true,
    
       spaceBetween: 19,
    
       scrollbar: {
          el: ".projects__swiper-scroll",
          draggable: true,
          dragSize: 80,
       },
    });

HTML HTML

<div class="projects__swiper-start swiper">
    <div class="projects__swiper swiper-wrapper">
        <div class="projects__swiper-slide swiper-slide">
            <div class="projects__swiper-img">
                <img src="images/projects/slide-1.jpg" alt="slide-1" />
            </div>
        </div>
        <div class="projects__swiper-slide swiper-slide">
            <div class="projects__swiper-img">
                <img src="images/projects/slide-2.jpg" alt="slide-2" />
            </div>
        </div>
        <div class="projects__swiper-slide swiper-slide">
            <div class="projects__swiper-img">
                <img src="images/projects/slide-3.jpg" alt="slide-3" />
            </div>
        </div>
        <div class="projects__swiper-slide swiper-slide">
            <div class="projects__swiper-img">
                <img src="images/projects/slide-4.jpg" alt="slide-4" />
            </div>
        </div>
    </div>
</div>

Now I have scrolled in full width, but I need to reduce it to 300px and place it in the center, as I found the slider to reduce, but with the width of the scroll, there is a problem.现在我已经全角滚动了,但是我需要将它减小到 300px 并将其放在中心,因为我发现 slider 减小了,但是随着滚动的宽度,出现了问题。

Thank you very much in advance!非常感谢您!

dragSize - Size of scrollbar draggable element in px. dragSize - 滚动条可拖动元素的大小,以 px 为单位。

在此处输入图像描述

No API option to control the width of swiper-scrollbar (The wrapper).没有 API 选项来控制swiper-scrollbar (包装器)的宽度。 If you change this by custom CSS you destroy the way the scrollbar works.如果您通过自定义 CSS 更改此设置,则会破坏滚动条的工作方式。

/* will not work as it should */
.swiper-horizontal .swiper-scrollbar{
  width: 50%!important;
}

You should open Github Feature Req related to this idea: https://github.com/nolimits4web/swiper/issues您应该打开与此想法相关的 Github Feature Req: https://github.com/nolimits4web/swiper/issues

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM