简体   繁体   English

隐藏水平滚动条,但使数据水平滚动

[英]Hide Horizontal Scroll Bar but make data scroll horizontally

I want to make image scroller where image can be scrolled horizontally but dont want horizontal scroll bar to be visible while scrolling. 我想制作可以在其中水平滚动图像的图像滚动器,但不希望水平滚动条在滚动时可见。 Below is the link to my codepen.. 以下是我的Codepen的链接。

http://codepen.io/rajMrPerfect/pen/PWewRM?editors=0100 http://codepen.io/rajMrPerfect/pen/PWewRM?editors=0100

<div class="scroll">
   <img src="http://placehold.it/100x100" />
   <img src="http://placehold.it/100x100" />
   <img src="http://placehold.it/100x100" />
   <img src="http://placehold.it/100x100" />
   <img src="http://placehold.it/100x100" />
   <img src="http://placehold.it/100x100" />
   <img src="http://placehold.it/100x100" />
   <img src="http://placehold.it/100x100" />
   <img src="http://placehold.it/100x100" />
   <img src="http://placehold.it/100x100" />
   <img src="http://placehold.it/100x100" />
   <img src="http://placehold.it/100x100" />
  </div>

.scroll {
    height: 180px;
    margin: auto;
    overflow-x: auto;
    overflow-y:hidden;
    white-space: nowrap;
    box-shadow: 0 0 10px #000;  
    img {
        margin: 20px 10px 0 10px;
    }
}

If you want an inivisble scrollbar you will need some javascript code to handle the scrolling. 如果您想要一个不可见的滚动条,则需要一些javascript代码来处理滚动。

I would use: https://github.com/asvd/dragscroll 我会使用: https : //github.com/asvd/dragscroll

Then: 然后:

 .scroll { height: 180px; margin: auto; overflow: hidden; white-space: nowrap; box-shadow: 0 0 10px #000; } img { margin: 20px 10px 0 10px; } 
 <script src="http://asvd.github.io/dragscroll/dragscroll.js"></script> <div class="scroll horizontal dragscroll"> <img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /><img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /><img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /><img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /><img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /> </div> 

Try: https://owlcarousel2.github.io/OwlCarousel2/demos/responsive.html 试试: https//owlcarousel2.github.io/OwlCarousel2/demos/sensitive.html

In the above examples, the items can be scrolled on "mouse click and drag" but you can extend the scroll by binding to the mousewheel. 在以上示例中,可以在“鼠标单击并拖动”上滚动项目,但可以通过绑定到鼠标滚轮来扩展滚动。

 .scroll { height: 180px; margin: auto; overflow: hidden; white-space: nowrap; box-shadow: 0 0 10px #000; } img { margin: 20px 10px 0 10px; } 
 <script src="http://asvd.github.io/dragscroll/dragscroll.js"></script> <div class="scroll horizontal dragscroll"> <img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /><img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /><img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /><img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /><img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /> </div> 

 .scroll { height: 180px; margin: auto; overflow: hidden; white-space: nowrap; box-shadow: 0 0 10px #000; } img { margin: 20px 10px 0 10px; } 
 <script src="http://asvd.github.io/dragscroll/dragscroll.js"></script> <div class="scroll horizontal dragscroll"> <img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /><img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /><img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /><img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /><img src="http://placehold.it/100x100" /> <img src="http://placehold.it/100x100" /> </div> 

This should work for Chrome 这应该适用于Chrome

::-webkit-scrollbar,
    *::-webkit-scrollbar {
        display: none;
    }

Another Solution would be (not really optimal) 另一个解决方案是(并非最佳)

-webkit-scrollbar {
    height: 0;
    width: 0;
}

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

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