javascript 在移动浏览器的 iScroll 中启用点击事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17768037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 09:32:16  来源:igfitidea点击:

Enable click events in iScroll on mobile browser

javascriptmobileiscrolliscroll4

提问by smstromb

I'm using iScroll to create a web app and I'm unable to click any divs that are within the iscroll wrapper. I tried setting eventPassthrough option to be true but it causes a significant amount of scrolling problems.

我正在使用 iScroll 创建一个 Web 应用程序,但无法单击 iscroll 包装器中的任何 div。我尝试将 eventPassthrough 选项设置为 true,但它会导致大量滚动问题。

Anyone experienced this?

有人经历过吗?

Edit: I'm using iScroll 5. The click events work chrome,firefox, and safari but not ios mobile safari.

编辑:我正在使用 iScroll 5。点击事件适用于 chrome、firefox 和 safari,但不适用于 ios mobile safari。

回答by fabio_biondi

Try setting the option "click: true"

尝试设置选项“click: true”

example:

例子:

myScroll = new IScroll('#wrapper', { click: true });

I had the same problem on IOS6 and it fixed the issue

我在 IOS6 上遇到了同样的问题,它解决了这个问题

回答by pistol-pete

I also ran into the same problem and began using the { click: true }approach (indicated above) as a solution. The problem with this approach is you will get two click events firing when viewed on the desktop (i.e. one event from actual mouse click, and one event from IScroll).

我也遇到了同样的问题并开始使用该{ click: true }方法(如上所示)作为解决方案。这种方法的问题是在桌面上查看时会触发两个单击事件(即一个来自实际鼠标单击的事件,一个来自 IScroll 的事件)。

The suggested approach per the IScroll documentationis to emit a custom 'tap' event using the IScroll options.

根据IScroll 文档建议的方法是使用 IScroll 选项发出自定义“点击”事件。

Example:

例子:

<script type="text/javascript">
    var scroller = new IScroll('#wrapper', { tap: true });
    $('#scroller').on('click, tap', '.clickable', function() {
        //do something....
    });
</script>

<div id="wrapper">
    <div id="scroller">
        <div class="clickable"></div>
        <div class="clickable"></div>
        <div class="clickable"></div>
    </div>
</div>

回答by Sumith Harshan

Try to add click: truefor iphone. Android worked for below both. But android worked without click: true.

尝试为 iPhone添加click: true。Android 适用于两者。但是 android 无需单击即可工作: true

myScroll = new IScroll('#myWrapper', { 
   tap: true, 
   click: true,    
});