zhaoda / spa

A webapp framework for routing control and view transitions
http://zhaoda.net/spa/docs/
MIT License
330 stars 92 forks source link

是不是跟fastclick有冲突,用了fastclick发现有些点击,第一次点击无效,第二次才可以点的动? #40

Closed jaryway closed 8 years ago

jaryway commented 8 years ago

如题 20160426222757

微信扫描感受一下。 选择客户 要点两次,还有相关人那里也是要点两次。IPhone 6s上

zhaoda commented 8 years ago

二维码扫描后打不开,有可能有冲突,没用过 fastclick,但是其他框架封装的 tap 事件不冲突,SPA的事件都是代理方式绑定的,有可能是 fastclick 阻塞了事件冒泡?或者逻辑上的问题?

On Tue, Apr 26, 2016 at 10:15 PM, jaryway notifications@github.com wrote:

如题 [image: qq 20160426221431] https://cloud.githubusercontent.com/assets/5987056/14821170/4a047a88-0bfc-11e6-8544-aa821535d547.png 微信扫描感受一下

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/zhaoda/spa/issues/40

zhaoda commented 8 years ago

我们项目中都是自行封装的 tap 事件,还能达到防治点击穿透的目的

2016-04-26 22:39 GMT+08:00 赵达 zd6437@gmail.com:

二维码扫描后打不开,有可能有冲突,没用过 fastclick,但是其他框架封装的 tap 事件不冲突,SPA的事件都是代理方式绑定的,有可能是 fastclick 阻塞了事件冒泡?或者逻辑上的问题?

On Tue, Apr 26, 2016 at 10:15 PM, jaryway notifications@github.com wrote:

如题 [image: qq 20160426221431] https://cloud.githubusercontent.com/assets/5987056/14821170/4a047a88-0bfc-11e6-8544-aa821535d547.png 微信扫描感受一下

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/zhaoda/spa/issues/40

jaryway commented 8 years ago

已经更新二维码,使用tap也是有问题,现在是使用click。使用tap覆盖的时候不能去除焦点,导致光标还在第一层。一闪一闪的在第一层

jaryway commented 8 years ago

@zhaoda 不用fastclick 用什么解决300ms延迟和tap穿透问题

zhaoda commented 8 years ago

@jaryway 给你一些代码作为参考,如果使用 Zepto 那么它封装的 tap 事件,否则自己封装也行。

下面的代码是在封装了 tap 事件的基础上。

  // 当前环境支持的点击事件
  var tapEvent = (function() {
    return "createTouch" in document ? 'tap' : 'click'
  })()

  // 禁止链接默认点击事件
  $doc.on('click', 'a.preventlink, a.taplink', function(event) {
    event.preventDefault()
    event.stopPropagation()
  })

  // 点击.taplink转场
  $doc.on(tapEvent, '.taplink', function(event) {
    var $currentTarget = $(event.currentTarget),
        $target = $(event.target),
        hash = $currentTarget.attr('href') || $currentTarget.attr('data-href')

    if($target.closest('.notaplink').length)
      return
    $doc.trigger('video:remove', {video: app.cache.curVideo})
    $currentTarget.trigger('spa:navigate', {hash: getHash(hash)})

    // event.preventDefault()
    // event.stopPropagation()
  })

  // 防止点击穿透
  if(tapEvent == 'tap') {
    $doc.on('touchstart', 'a', function(event) {
      var $target = $(event.currentTarget)
      $target.data('taptime', +new Date())
    })

    $doc.on('click', 'a', function(event) {
      var $target = $(event.currentTarget),
          taptime = $target.data('taptime')

      if(!taptime || (+new Date() - taptime > 500)) {
        event.preventDefault()
        event.stopPropagation()
      }
    })
  }
jaryway commented 8 years ago

@zhaoda 大概明白了你处理tap点透的思路。但是,好像在我的这里不起作用。根据你的思路,我是这样子处理的:

if (tapEvent == 'tap') {
        app.common.$doc.on('touchend', ".stopclick", function (event) {
            var $target = $(event.target);
            //taptime = $target.data('taptime'),
            //stopclick = $target.data('stopclick')
            //_log(stopclick);
            event.preventDefault()
            event.stopPropagation()
            return false;
        })
    }

题外话 我觉得这个框架挺好的: 1、有一个漂亮的转场动画; 2、每个页面的脚本相对独立,不会出现脚本互串的问题,事件互串的问题; 3、页面只在首次打开时有loading,第二次打开反应快,减少了页面的抖动。 但对数据时效性要求较高的页面只能用 nocache: true(不缓存页面)来做。比如,从详细页进入编辑页,修改某项数据后返回详细页,此时发现详细页的数据依然没有更新。不知是否还有更好的方式?

zhaoda commented 8 years ago

在特定页面里,通过beforeopen事件主动清理一下页面的数据和渲染

2016-07-19 16:16 GMT+08:00 Jaryway notifications@github.com:

@zhaoda https://github.com/zhaoda 大概明白了你处理tap点透的思路。但是,好像在我的这里不起作用。根据你的思路,我是这样子处理的:

if (tapEvent == 'tap') { app.common.$doc.on('touchend', ".stopclick", function (event) { var $target = $(event.target); //taptime = $target.data('taptime'), //stopclick = $target.data('stopclick') //_log(stopclick); event.preventDefault() event.stopPropagation() return false; }) }

题外话 我觉得这个框架挺好的: 1、有一个漂亮的转场动画; 2、每个页面的脚本相对独立,不会出现脚本互串的问题,事件互串的问题; 3、页面只在首次打开时有loading,第二次打开反应快,减少了页面的抖动。 但对数据时效性要求较高的页面只能用 nocache: true(不缓存页面)来做。比如,从详细页进入编辑页,修改某项数据后返回详细页,此时发现详细页的数据依然没有更新。不知是否还有更好的方式?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zhaoda/spa/issues/40#issuecomment-233562245, or mute the thread https://github.com/notifications/unsubscribe-auth/AAhXY3uMeTGowFGLhX2sDgyoL5HCe3hgks5qXIf2gaJpZM4IP_lJ .

zhaoda commented 8 years ago

@jaryway 你好,还在用 SPA 么?问题解决否?