这个想法是有一个黑白的图片,并在‘鼠标移动’使用SVG剪裁图像“获得颜色”(跟随我的鼠标移动)。我通过获取鼠标坐标并用彩色版本裁剪黑白图片来做到这一点。它在桌面上与每个浏览器都能完美地工作。
var clientX = 0;
var clientY = 0;
getCoordinates = function(event) {
clientX = event.clientX;
clientY = event.clientY;
};
updateRect = function() {
creative.dom.rect.setAttribute('x', clientX);
creative.dom.rect.setAttribute('y', clientY);
};
clipThroughImage = function() {
updateRect();
};
creative.dom.imageBw.addEventListener('mousemove', getCoordinates);
creative.dom.imageBw.addEventListener('mousemove', clipThroughImage);然而,在移动设备上,剪辑只能通过点击来“工作”(当我保持‘mousemove’时)。当我点击的时候,颜色就会立即显示出来,而不是随着手指的移动而改变颜色(就像鼠标一样)。
我试着使用了“touchmove”,但它根本不起作用,它只是剪切了整个彩色图像,仅此而已。
我需要更改什么才能在移动设备上获得相同的结果?
发布于 2017-04-21 23:33:51
使其在以下情况下工作:
var allowSwipe = true;
getCoordinates = function(event) {
if (!allowSwipe) return;
allowSwipe = false;
setTimeout(function() {
allowSwipe = true;
}, 10);
clientX = (event.clientX || event.touches[0].clientX);
clientY = (event.clientY || event.touches[0].clientY);
clipThroughImage();
};
creative.dom.imageBw.addEventListener('touchmove', getCoordinates);
creative.dom.imageBw.addEventListener('mousemove', getCoordinates);代码的其余部分仍然是一样的。
https://stackoverflow.com/questions/43545185
复制相似问题