-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
29 lines (25 loc) · 1005 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
(function() {
var svgElement = document.querySelector('svg');
var maskedElement = document.querySelector('#mask-circle');
var circleFeedback = document.querySelector('#circle-shadow');
var svgPoint = svgElement.createSVGPoint();
function cursorPoint(e, svg) {
svgPoint.x = e.clientX;
svgPoint.y = e.clientY;
return svgPoint.matrixTransform(svg.getScreenCTM().inverse());
}
function update(svgCoords) {
maskedElement.setAttribute('cx', svgCoords.x);
maskedElement.setAttribute('cy', svgCoords.y);
circleFeedback.setAttribute('cx', svgCoords.x);
circleFeedback.setAttribute('cy', svgCoords.y);
}
window.addEventListener('mousemove', function(e) {
update(cursorPoint(e, svgElement));
}, false);
document.addEventListener('touchmove', function(e) {
e.preventDefault();
var touch = e.targetTouches[0];
if (touch) update(cursorPoint(touch, svgElement));
}, false);
})();