Javascript 在SVG上使用';mousemove';移动设备的鼠标位置选择
想法是有一个黑白图片,在“mousemove”上使用SVG剪裁图像“增益颜色”(跟随我的鼠标移动)。我通过获取鼠标坐标并用彩色版本剪裁黑白图片来实现这一点。它可以在桌面上与所有浏览器完美配合Javascript 在SVG上使用';mousemove';移动设备的鼠标位置选择,javascript,svg,mobile,Javascript,Svg,Mobile,想法是有一个黑白图片,在“mousemove”上使用SVG剪裁图像“增益颜色”(跟随我的鼠标移动)。我通过获取鼠标坐标并用彩色版本剪裁黑白图片来实现这一点。它可以在桌面上与所有浏览器完美配合 var clientX = 0; var clientY = 0; getCoordinates = function(event) { clientX = event.clientX; clientY = event.clientY; }; updateRect = function() {
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”,但它根本不起作用,它只是剪辑了整个彩色图像,仅此而已
要在移动设备上获得相同的结果,我需要做哪些更改?使其与以下各项配合使用:
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);
剩下的代码还是一样的