I'm currently using the following code below using jQuery and the hover function to fade in a the 'caption' element when the user hovers over the image. This works perfectly on desktop browsers, however when testing it with mobile touch devices such as iPad which requires the user to tap the image to trigger the hover function the caption fades in as expected but stays active until the user selects another object on the page.
I would like to know a simple way to modify my javascript code to detect mobile touch devices and then put some sort or timer to the caption so that it fades back automatically after a period of time?
<!-- include jQuery library -->
<script type="text/javascript" src="./_js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//On mouse over those thumbnail
$('.item-caption').hover(function() {
//Display the caption
$(this).find('.caption').stop(false,true).fadeIn(200);
},
function() {
//Hide the caption
$(this).find('.caption').stop(false,true).fadeOut(600);
});
});
</script>
</head>
<body>
<div class="item-caption"><a href="http://www.domain.com">
<div class="caption">
<ul>
<li><h2>TITLE</h2></li>
<li><h3>Description</h3></li>
</ul>
</div>
<img src="./_img/example_image.jpg"></a>
</div>
</body>
Any ideas, thoughts would be most appreciated.
Chris