const updateCoordinates = e => { if(coordinates.x === undefined || coordinates.y === undefined){ coordinates.x = e.x; coordinates.y = e.y; addElement(); } if(Math.abs(coordinates.x - e.x) > 50 || Math.abs(coordinates.y - e.y) > 50) { coordinates.x = e.x; coordinates.y = e.y; addElement(); } } header.addEventListener('mousemove', e => { updateCoordinates(e); });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter