[英]touch event not working on android
I built a spotlight style overlay that works fine on iphones/tablets/and pc but it's not working on android devices. 我建立了一个Spotlight样式的叠加层,该叠加层在iPhone /平板电脑/和PC上正常运行,但在Android设备上不起作用。 here's what I'm working with:
这是我正在使用的:
<script type="text/javascript">
var spot = document.getElementById('spot');
var width = document.documentElement.clientWidth;
var height = document.documentElement.clientHeight;
/* A bit of JS to respond to mouse events */
function moveSpot(e){
var x = 0;
var y = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY)
{
x = e.pageX;
y = e.pageY;
}
else if (e.clientX || e.clientY)
{
x = e.clientX + document.body.scrollLeft;
y = e.clientY + document.body.scrollTop;
}
var style = '-webkit-gradient(radial, '+x+' '+y+', 0, '+x+' '+y+', 100, from(rgba(0,0,0,0)), to(rgba(0,0,0,1)), color-stop(0.8, rgba(0,0,0,0)))';
spot.style.backgroundImage = style;
}
window.onload = function() {
//window.onmousemove = moveSpot;
window.ontouchmove = moveSpot;
}
</script>
some direction as to the issue would be appreciated. 关于这个问题的一些方向将不胜感激。
I figured it out. 我想到了。 Essentially you need to change e.pageX and e.pageY to event.touches[0].pageX and event.touches[0].pageY also within the code call event.preventDefault();
本质上,您还需要在代码调用event.preventDefault();中将e.pageX和e.pageY更改为event.touches [0] .pageX和event.touches [0] .pageY。 this seemed to resolve the issue.
这似乎解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.