我怎么能说如果它是一个触摸设备不要悬停并直接点击?
这是播放的示例:http: //jsfiddle.net/2Sax4/4/
关键是怎么说得到a href。像这样的东西:
window.location= 'http://' + this a;
jQuery:
$(function(){
// not touch:
$(".menu li").hover(function() {
$(this).animate({ "background-color":red }, 1000);
},function() {
$(this).animate({ "background-color":blue }, 1000);
});
// touch:
var supportsTouch = 'ontouchstart' in window || 'onmsgesturechange' in window;
if(supportsTouch) {
$(this).on('touchstart', function(){
//I tried something like this
window.location= 'http://' + this a;
});
}
})
HTML:
<ul class="menu">
<li id="first"><a href="first.html">first</a></li>
<li id="second"><a href="second.html">second</a></li>
</ul>