jquery - 使用ajax调用在移动设备上滚动页面时防止touchstart
问题描述
通常这将是代码:
var touchmoved;
$('button').on('touchend', function(e){
if(touchmoved != true){
// you're on button click action
}
}).on('touchmove', function(e){
touchmoved = true;
}).on('touchstart', function(){
touchmoved = false;
});
但是,此代码似乎不适用于动态生成的 ajax 元素。
为此,我有以下代码:
var touchmoved;
$(document).on('click touchend', '.menu', function(){
if(touchmoved != true){
// you're on button click action
}
}).on('touchmove', '.menu', function(e){
touchmoved = true;
}).on('touchstart', '.menu', function(){
touchmoved = false;
});
现在它适用于网络界面,但似乎不适用于移动界面。
是否可以制作一个工作区,以便我可以动态地进行 ajax 调用并使其正常工作?
解决方案
原来我最初发布的代码是正确的答案。
我正在使用一个名为 nicescroll 的第 3 方脚本,它在我下载的版本中有一些错误。
因此,对于后代,(目前)防止动态生成元素的 touchstart 的方法是:
var touchmoved;
$(document).on('click touchend', '.menu', function(){
if(touchmoved != true){
// your click action here!!!
}
}).on('touchmove', '.menu', function(e){
touchmoved = true;
}).on('touchstart', '.menu', function(){
touchmoved = false;
});
推荐阅读
- c - 左移运算符是否依赖于寄存器大小?
- matlab - 在matlab中获得每米像素很热
- python - 无法在 django oscar 中获得零售价
- gatsby - 防止 Gatbsy 中某些组件或语句的补液
- ios - 使用 Cocoapods 示例应用程序为框架构建问题
- java - 创建脚本以在不同的终端窗口中运行多个 java jar
- node.js - 如何同时启动我的节点服务器和响应应用程序?
- python - 如何在不同环境中仅部署增量更改/文件?
- java - 内联 Thread 对象比从 Thread 继承的类运行得快得多
- r - Corrplot.mixed 图(数字和平方一起)