我目前正在使用下面的代码使用jQuery和悬停函数来淡入当用户悬停在图像上的'标题'元素。这在桌面浏览器上完美运行,但是当使用iPad等移动触摸设备进行测试时,需要用户点击图像以触发悬停功能,字幕按预期淡入,但保持活动状态,直到用户在页面上选择另一个对象。超时jQuery悬停功能
我想知道一个简单的方法来修改我的javascript代码来检测移动触摸设备,然后把一些排序或计时器的标题,以便它在一段时间后自动淡化?
<!-- 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>
任何想法,想法将不胜感激。
克里斯
用户代理检测是一个可怕的想法 - 特征检测几乎总是一个更好的方式去。如果您想要检测触摸行为,则可以在Touch上使用功能检测。有关信息,请参阅http://stackoverflow.com/questions/4643443/how-do-i-detect-whether-a-browser-supports-mouseover-events。 – jfriend00