JSFiddle - React, Tailwind, and code Playground
by simoncereska
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
<button id="lorem" type="button">
Click Final
</button>
JavaScript
var hasTouch = (function(){
var deviceAgent = navigator.userAgent.toLowerCase();
return Modernizr.pointerevents ||
Modernizr.touchevents ||
Modernizr.hiddenscroll ||
window.onmsgesturechange ||
('ontouchstart' in window) ||
('ontouchend' in window) ||
window.DocumentTouch && document instanceof DocumentTouch ||
navigator.msMaxTouchPoints > 0 ||
navigator.maxTouchPoints > 0 ||
deviceAgent.match(/(iphone|ipod|ipad)/) ||
deviceAgent.match(/(android)/) ||
deviceAgent.match(/(iemobile)/) ||
deviceAgent.match(/iphone/i) ||
deviceAgent.match(/ipad/i) ||
deviceAgent.match(/ipod/i) ||
deviceAgent.match(/blackberry/i) ||
deviceAgent.match(/bada/i) ||
window.matchMedia('(pointer:coarse)').matches;
})();
alert(('onmousedown' in window));
window.addEventListener('touchstart', function setHasTouch () {
alert('THIS is TOUCH')
hasTouch = true;
// Remove event listener once fired, otherwise it'll kill scrolling
// performance
window.removeEventListener('touchstart', setHasTouch);
}, false);
/*
window.addEventListener('click', function setHasClick () {
alert('THIS is click')
hasTouch = true;
// Remove event listener once fired, otherwise it'll kill scrolling
// performance
window.removeEventListener('touchstart', setHasClick);
}, false);
*/