JSFiddle - React, Tailwind, and code Playground
HTML
<div class="parent">
<span>Peek-A-</span>
<div class="child">
<span>Boo</span>
</div>
</div>
CSS
.child {
display: none;
}
JavaScript
$(document).ready(function() {
function hasTouch() {
try {
document.createEvent("TouchEvent");
return (true);
} catch (e) {
return (false);
}
}
var touchPresent = hasTouch();
$('.parent').hover(function() {
var caption = $(this).find('.child');
caption.stop(true, true).fadeIn("fast");
if (touchPresent) {
$('.parent').on("touchstart", function(e) {
$(this).children(".child").fadeToggle("fast");
});
}
}, function() {
$(this).find('.child').stop(true, true).fadeOut("fast");
});
});