我有一个具有悬停效果的按钮。 但是我想禁用 ipad 和 iphone 中的悬停。 它不工作
$(document).ready(function () {
$(".content").hide();
$(".open1").click(function () {
$(this).next().slideToggle(400);
if('ontouchstart' in document){$('#btn_01').unbind('mouseenter mouseleave');}
var btn = $('#btn_01'), isOn = btn.hasClass('on');
if(isOn) { btn.removeClass('on'); }
else if(btn) { btn.addClass('on'); }
});
});
<style type="text/css">
#btn_01{width:510px; height:109px; background:url('images/btn_01_on.png') no-repeat;}
#btn_01:hover{width:510px; height:109px; background:url('images/btn_01_over.png') no-repeat;}
#btn_01.on{width:510px; height:109px; background:url('images/btn_01_over.png') no-repeat;}
最佳答案
我会采用不同的方法:
jQuery(function($) {
var className = ('ontouchstart' in document ) ? "touch-device" : "desktop-device";
$(document.body).addClass(className);
});
然后您可以使用 body.desktop-device
和 body.touch-device
指定您的样式调整:
body.desktop-device #btn_01:hover {
background: red;
}
body.touch-device #btn_01 {
background: blue;
}
var a = b ? c : d;
//means:
if ( b ) {
var a = c;
}
else {
var a = d;
}
关于javascript - ontouchstart 删除 ipad iphone 中的悬停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15114731/