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

怎么做移动端点击延迟处理? #3135

Closed
apgyapgy opened this issue Apr 22, 2020 · 2 comments
Closed

怎么做移动端点击延迟处理? #3135

apgyapgy opened this issue Apr 22, 2020 · 2 comments

Comments

@apgyapgy
Copy link

vue-element-admin做了移动端的适配,没有做点击延迟处理。我加入了fastclick会出现el-checkbox点击选不中的情况,该怎么处理。找了好久没找到解决方法。

@dingangang
Copy link
Contributor

这是fastclick的问题。
1、请保存fastclick.js至public
2、修改index.html head中添加
` <script src="fastclick.js"></script>

<script>
  window.onload=function () {
    // 引入fastclick
    if ('addEventListener' in document) {
      FastClick.attach(document.body);
    }
    // ios user-scale 失效处理
    document.addEventListener('touchstart',function (event) {
      if(event.touches.length>1){
        event.preventDefault();
      }
    });
    var lastTouchEnd=0;
    document.addEventListener('touchend',function (event) {
      var now=(new Date()).getTime();
      if(now-lastTouchEnd<=300){
        event.preventDefault();
      }
      lastTouchEnd=now;
    },false);
    document.addEventListener('gesturestart', function (event) {
      event.preventDefault();
    });
  }
</script>`

3、问题关键,点击el-checkbox 事件触发dom为 span.el-checkbox__label 所以单纯的给组件添加类名 needsClick 也不能解决问题。所以我们需要手动修改一下fastclick.js的源码
4、最直观的方式是 FastClick.prototype.needsClick return 部分 修改为

return (/\bneedsclick\b/).test(target.className) || (/\bel-checkbox__label\b/.test(target.className));

直接将el-checkbox硬编码排除fastclick的作用范围。有其他元素出问题的时候,可以在 FastClick.prototype.needsClick中debugger查看具体触发click的dom

@PanJiaChen
Copy link
Owner

PanJiaChen commented May 5, 2020

楼上说的相当详细了,给个赞

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

3 participants