Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在手机上手指滚动屏幕的时候,会触发页面元素的点击事件 #8

Open
fisherw opened this issue Jun 14, 2017 · 5 comments

Comments

@fisherw
Copy link

fisherw commented Jun 14, 2017

现象就是我滚着页面就触发了页面元素中的按钮点击,希望可以优化一下。

@HcySunYang
Copy link
Owner

单凭这句话我很难准确的定位真正的问题所在,不过我可以猜测一下:
你的按钮是不是使用了 touchstart/touchend 事件,而不是click事件?

@fisherw
Copy link
Author

fisherw commented Jun 14, 2017

场景:页面元素中有按钮(我只监听onclick事件),手机上手指触屏滚动时,当手指刚好触到按钮的时候,会触发按钮的点击。

这个应该很容易重现到。

@zaxlct
Copy link
Collaborator

zaxlct commented Jun 14, 2017

@fisherw
Talk is cheap. Show me the code.

@fisherw
Copy link
Author

fisherw commented Jun 15, 2017

。。。。

@keepfool
Copy link

keepfool commented Jul 25, 2017

场景:在一个宫格页面,每个宫格绑定click事件,上滑或者下滑时可能会触发宫格的click事件。
解决方法,修改src/fingerd.js,在处理touchend和touchcancel时阻止事件冒泡

injectEvent (event) {
        if (eventType === EVENT_TYPE.touchend || eventType === EVENT_TYPE.touchcancel) {
            // 阻止事件冒泡,避免在滚动时触发页面元素的click事件
            event.cancelBubble = true
        }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants