AngularJS:ngTouch 300 毫秒延迟 [英] AngularJS: ngTouch 300ms Delay

查看:21
本文介绍了AngularJS:ngTouch 300 毫秒延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个 Plunkr 有 2 个链接.左侧的一个是使用 ng-click 指令,并插入了 on angular-touch 模块.正如 ng-click 的 angular touch module description 所述,ng-click 链接不应有 300 毫秒的延迟.但如果您在移动设备上进行测试,情况仍然如此.

This Plunkr has 2 links. The one on the left side is using the ng-click directive with the on angular-touch module inserted. As said in the angular touch module description for ng-click, the ng-click link should not have a 300ms delay. But if you test it on mobile devices, this is still the case.

那么 plunkr 是否阻止了正确的功能,因为它在 iFrame 或类似的东西中执行,或者是否需要将 Fastclick.js 插入到项目中才能使指令正常工作?我不明白,请帮忙.

So is plunkr preventing the correct functionality because its executed in an iFrame or something like that or is it required to insert Fastclick.js into the project for the directive to work correctly ? I don't get it, please help.

示例:http://plnkr.co/NRRrmMFaIKg2zLu5C1Tg

angularjs 中的示例文档也不起作用.他们甚至没有插入 angular-touch 模块.

edit: the example in the angularjs docs ist not working either. They didn't even inserted the angular-touch module.

推荐答案

因为 angulars ngTouch 模块只消除了 ng-click 指令上的 300 毫秒延迟,我正在使用 fastclick.js 现在与 angular 完美协调.

Because angulars ngTouch module is only removing the 300ms delay on ng-click directives, i'm using fastclick.js now which harmonates perfectly fine with angular.

一开始它对我不起作用,因为我在加载脚本之前,在 DOM 准备好之前附加了 Fastclick 库.我通过将函数包装在我的 angular 应用程序的运行块中来解决这个问题.该函数在 DOM 准备好后执行代码.

At the beginning it did not work for me, because I attached the Fastclick library before its script was loaded, before the DOM was ready. I fixed this by wrapping the function in the run block of my angular app. This function executes code after the DOM is ready.

angular.module('myModule', []).
  run(function() {
    FastClick.attach(document.body);
  });

angularjs youtube 频道上的最新截屏视频建议了这种方式.

This way is suggested by the latest screencast on the angularjs youtube channel.

这篇关于AngularJS:ngTouch 300 毫秒延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆