タッチデバイスの場合、ホバーせずに直接クリックするとどのように言えますか?
再生する例は次のとおりです: 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>