此SVG交互式语言使用普通JavaScript(无jQuery)编写,可在除iOS移动Safari之外的所有浏览器中使用。我了解iOS移动Safari中的事件处理程序存在已记录的问题。我已经尝试过堆栈溢出建议的解决方法。显而易见的是:
HTML div id =“ canvas” onclick =“ void(0);”
hexGroup.addEventListener("touchstart", start, false);
hexGroup.addEventListener("mouseenter", start, false);
function start(event) {
var self = this;
self.setAttribute("class", "hover");
self.remove();
svg.appendChild(self);
};
// clear class
hexGroup.addEventListener("mouseleave", end, false);
hexGroup.addEventListener("touchend", end, false);
function end(event) {
this.setAttribute("class", "");
};
hexGroup.addEventListener("touchmove", moveOrCancel, false);
hexGroup.addEventListener("touchcancel", moveOrCancel, false);
function moveOrCancel(event) {
event.preventDefault();
this.setAttribute("class", "");
};
我只能触发触摸开始,而不能触发触摸结束。
使用this link在iPhone上进行测试 我的测试使用SauceLabs所有版本的iOS和虚拟iPhone。
代码在codepen
上