Is there any CSS Hover for touch? Or way to emulate one with javascript that only activates if it is touch?
Is there any CSS Hover for touch? Or way to emulate one with javascript that only activates if it is touch?
My solution was this:
window.onload = function(e){
x = document.getElementById('x');
x.addEventListener("touchstart", touch);
x.addEventListener("touchend", touch);
x.addEventListener("mousemove", mouse);
x.addEventListener("mouseout", mouse);
function touch(event){
if(event.type == 'touchstart'){
setTimeout(function(){
x.style.background = 'blue';
}, 200);
}
if(event.type == 'touchend'){
setTimeout(function(){
x.style.background = 'red';
}, 3000);
}
}
function mouse(event){
if(event.type == 'mousemove'){
x.style.background = 'blue';
}
if(event.type == 'mouseout'){
x.style.background = 'red';
}
}
}
#x{
height: 300px;
width: 300px;
background: red;
}
<div id="x"></div>