JSFiddle - React, Tailwind, and code Playground
HTML
<a href="#">gdfgfg</a>
JavaScript
var a=(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)?'touchstart,touchmove,touchend':'mousedown,mousemove,mouseup').split(','),//a=array
b=a.length,//length
sx,//startx
sy,//starty
st,//startTime
ex,//endx
ey,//endy
et,//endtome
dt=Date.now,//datenow
abs=Math.abs,
max=Math.max,//math
mv,//moved
mu;//mousedown
function c(e,d){
d=e.type;f=e.target;
return d===a[1]?
(mu||(//pressed
ex=e.x||e.touches[0].pageX,
ey=e.y||e.touches[0].pageY//,
//et=dt()
,mv||(mv=true)
)):
d==a[2]?
(mu=true,(
(mv||ce(e,'fc')),
//((20<max(abs(ex-sx),abs(ey-sy))&&mv)||ce(e,'fclick')),
//console.log('duration:',dt()-st),
//console.log('speed:',max(abs(ex-sx),abs(ey-sy))/((dt()-st)/1000)),
//console.log('up:',ex,ey,dt()),
mv=false
)):
(mu=false,(
sx=e.x||e.touches[0].pageX,
sy=e.y||e.touches[0].pageY,
st=dt(),
mv=false//,
//console.log('down:',sx,sy,st)
));
//console.log(mu);
}
function ce(e,n){
console.log(n,e.target);
var a=document.createEvent("CustomEvent");
a.initCustomEvent(n,true,true,e.target);
e.target.dispatchEvent(a);
a=null;
return false
}
while(b--){
window.addEventListener(a[b],c,false)
}
function ch(e){
console.log(e)
}
window.onload=function(){
var link=document.getElementsByTagName('a')[0];
link.addEventListener('fc',ch,false);
}