我正在尝试跨浏览器设置指针事件。现在,大多数浏览器已经支持它,但 iOs 上的 safari 不支持。所以我试图用 pep-js 填充它,但没有成功。这是我的测试代码:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.pep/0.4.0/jquery.pep.min.js"></script>
<meta charset="utf-8">
<style>
.pixel {position: absolute;background: black;width: 2px;height:2px;}
#canvas {margin: 20px;background: white;border: 1px solid black;height: 200px;}
</style>
</head>
<body>
<div id="canvas" touch-action="none"></div>
<script>
function draw(where) {
var div = document.createElement('div');
div.classList.add('pixel');
div.setAttribute('style', 'left:'+where.pageX + 'px;top:'+where.pageY+'px');
document.querySelector('#canvas').appendChild(div);
}
document.querySelector('#canvas')
.addEventListener('pointermove', function(event) {
draw(event);
});
</script>
</body>
</html>
或我在 jsffidle 上创建的另一个
在桌面上它就像一个魅力,但 iOS 上的 safari 却没有。有什么建议我做错了吗?
最佳答案
看来您使用了错误的库。
您使用 jquery.pep.js但可能想要PEP .这是一个不幸的命名冲突。
关于javascript - PepJs/pointer-event polyfill 不适用于 iOs safari,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43127075/