Hallo Beat,
So diesmal eine getestete Version
var eventSupport={ 'pointerdown': ('onpointerdown' in window)? true : false, 'mousedown': ('onmousedown' in window)? true : false, // ... }; //console.log(eventSupport); function pickEvent(chooseFrom){ while(chooseFrom.length > 0){ var type = chooseFrom.shift(); if(eventSupport[type] == true ) return type; } } // später var el = document.body; //console.log(el); //console.log(pickEvent(["pointerdown","mousedown"])); el.addEventListener(pickEvent(["pointerdown","mousedown"]), function(ev){console.log(ev);} );
jetzt fehlt nur noch der touchstart
. Im Wiki-Artikel sieht es dann so aus:
// Ermitteln der unterstützten Methoden
var can_touch = ("TouchEvent" in window);
var can_pointer = ("PointerEvent" in window);
// Die Eventhandler für pointer-, touch- und mouse-Events setzen
if(can_pointer) {
roi.style.touchAction = "none";
roi.addEventListener("pointerdown",start_roi,false);
roi.addEventListener("pointermove",move_pointer,false);
roi.addEventListener("pointerup",end_move,false);
}
else {
if(can_touch) {
roi.addEventListener("touchstart",start_roi,false);
roi.addEventListener("touchmove",move_touch,false);
roi.addEventListener("touchend",end_move,false);
}
roi.addEventListener("mousedown",start_roi,false);
roi.addEventListener("mousemove",move_mouse,false);
roi.addEventListener("mouseup",end_move,false);
}
Gruß
Jürgen