在iphone的表格单元格上触摸事件
touch events over table cells in iphone
我有一个由6列8行组成的表。
<table border="1" id="patterntable" style="cursor: pointer;">
<tr>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
</tr>
<tr>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
</tr>
<tr>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
</tr>
<tr>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
</tr>
<tr>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
</tr>
<tr>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
<td align="center" width="40" height="40" > </td>
</tr>
<tr>
<td align="center" height="40" > </td>
<td align="center" height="40" > </td>
<td align="center" height="40" > </td>
<td align="center" height="40" > </td>
<td align="center" height="40" > </td>
<td align="center" height="40" > </td>
</tr>
<tr>
<td align="center" height="40" > </td>
<td align="center" height="40" > </td>
<td align="center" height="40" > </td>
<td align="center" height="40" > </td>
<td align="center" height="40" > </td>
<td align="center" height="40" > </td>
</tr>
</table>
我必须做到,当用户触摸并移动表格的单元格时,这些单元格将填充一些字母或符号。我试过跟随,但它不起作用,它只填充了我开始触摸的第一个单元格。
$("#patterntable td").on("touchmove",function(ev){
ev.preventDefault();
var e = ev.originalEvent;
$.each( e.touches, function( key, value ) {
var touch = e.touches[key];
if (touch.target.innerText != "'xA0"){
touch.target.innerText = "'xA0";
} else {
touch.target.innerText = patternSymbol;
}
});
});
请有人帮忙。
我也遇到过类似的问题——我用一张复选框表制作了一个生活游戏的HTML端口。我能够创建一个很酷的鼠标向下界面,允许"玩家"在鼠标向下时拖动鼠标在棋盘上画画,并希望对触摸设备也这样做。
不幸的是,触摸事件只保存对其开始位置(即"touchstart"激发位置)的DOM元素的引用,而不识别其下存在的DOM元素。相反,触摸事件维护了触摸对象的几个列表,这些列表表示与触摸屏的交互。这些对象的属性包括clientX和clientY,它们指示事件相对于视口的X和Y坐标。
我决定看看DOM是否提供了一个查找函数,可以根据这些坐标识别DOM元素,并找到了"document.elementFromPoint",这要归功于以下问题:通过绝对坐标定位DOM元素。
最后,我创建了一个"touchmove"事件监听器,该监听器使用相关触摸事件的坐标调用elementFromPoint方法(对我来说,这是e.touch[0]),然后对elemet进行适当的更改(在我的情况下,切换textbox checked属性)。这是一个事件监听器:
//this.gameGrid is a parent element for the checkboxes
this.gameGrid.addEventListener("touchmove", function(e) {
// get the touch element
var touch = e.touches[0];
// get the DOM element
var checkbox = document.elementFromPoint(touch.clientX, touch.clientY);
// make sure an element was found - some areas on the page may have no elements
if (checkbox) {
// interact with the DOM element
checkbox.checked = !checkbox.checked;
}
...
});
可以在这里找到一个工作示例的链接、该示例的完整源代码以及关于我对这个答案的研究的更多注释:https://gist.github.com/VehpuS/6fd5dca2ea8cd0eb0471
相关文章:
- 谷歌地图劫持了iphone's滚动(触摸事件)-如何恢复
- 如何使用纯javascript的移动触摸事件
- 移动定时触摸事件
- 模拟html5的触摸事件
- Phonegap/Cordova:如何添加Javascript多点触摸事件
- 如何在AngularJS中监听点击事件,而不是触摸事件
- 我可以让我的网站的内容可编辑区域对安卓股票浏览器上的触摸事件更敏感吗
- 在 Firefox 中“解析”触摸事件
- 将触摸事件转换为鼠标事件仅每秒有效一次
- 在移动 Safari 上向下拖动时,触摸事件停止触发 - iPad HTML5
- 如何在 javascript 中触发触摸事件
- 为什么触摸事件不在手指按压的中间
- 如何启用离子多点触摸事件
- 当我将位置更改为绝对时,画布精灵表和触摸事件不起作用
- 当元素在事件绑定后附加到DOM时,触摸事件不起作用
- JavaScript的触摸事件
- Tizen可穿戴设备屏幕顶部的Javascript触摸事件
- 用标准javascript而不是jquery中的mousedown、mousemove和mouseup触摸事件句柄
- (窗口中的'ontouchstart')返回true,但没有触摸事件
- 传单触摸事件未触发