简体   繁体   English

iScroll隐藏/显示滚动条

[英]iScroll hide/show scrollbar

I am trying to implement a hover feature on my iScroll div, where I am able to show/hide the scrollbar. 我正在尝试在我的iScroll div上实现悬停功能,在这里我可以显示/隐藏滚动条。 I'd like to have the user hover over the div and have the scrollbar appear and once the user moves the mouse off the container the scrollbar disappears. 我想让用户将鼠标悬停在div上并显示滚动条,并且一旦用户将鼠标移开容器,滚动条就会消失。

I've been looking into this to see if its possible but havent had much luck trying to find a solution. 我一直在调查这件事,以查看是否有可能,但是没有足够的运气试图找到解决方案。 I've found that iScroll has a hideScrollbar parameter that I can be set when initializing the new iScroll object but not entirely sure how to dynamically set the parameter based on the users interaction with the scroll container. 我发现iScroll有一个hideScrollbar参数,在初始化新的iScroll对象时可以设置该参数,但不能完全确定如何根据用户与滚动容器的交互来动态设置该参数。

Any help would be greatly appreciated. 任何帮助将不胜感激。

The below code will give what you want. 下面的代码将提供您想要的。 :) (Tested Desktop & Android & iOS); :)(经过测试的台式机,Android和iOS);

hideScrollbar: !isIDevice || isIDevice || isAndroid,
fadeScrollbar: !isIDevice || isIDevice && has3d,

This is the same line with vletech said before 112-113. 这与vletech在112-113之前所说的相同。

I can't seem to find the parameter hideScrollbar as you mentioned above, but an easy way around this would be to add your own fade animation on it. 我似乎找不到如上所述的参数hideScrollbar ,但是解决此问题的一种简单方法是在其上添加自己的淡入淡出动画。

Eg 例如

$('#DivToHover').hover(
   function(){
      $('#ScrollBarDiv').fadeIn("fast");
   },
   function(){
      $('#ScrollBarDiv').fadeOut("fast");
   }
);

But this might cause some problems if you're expecting this to be viewable on mobile devices. 但这可能会导致一些问题,如果您希望在移动设备上可以看到此问题。

EDIT 编辑

Change line 35 to. 将第35行更改为。

isIDevice = (/iphone|ipad|Mozilla/gi).test(navigator.appVersion),

EDIT 2 Thinking about this again a better way would be to leave line 35 as it is (/iphone|ipad/gi) . 编辑2再次考虑这个更好的方法将是保留行35 (/iphone|ipad/gi) But change lines 112 & 133 to ... 但是将112和133行更改为...

hideScrollbar: isIDevice && !isIDevice,
fadeScrollbar: isIDevice && !isIDevice && has3d,

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

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