【发布时间】:2013-01-01 13:35:54
【问题描述】:
我有一个悬停功能,如果它是一个触摸设备,我希望悬停事件不会发生。问题是当您使用触摸设备点击链接时,它会在执行点击事件之前执行悬停事件,因此您必须点击它两次才能使其工作。
这是悬停功能:
$("#close").hover(
function () {
$("#close_2").css({
display: "none"
});
$("#close_1").css({
display: "block"
});
},
function () {
$("#close_1").css({
display: "none"
});
$("#close_2").css({
display: "block"
});;
}
);
然后我将其设置为点击功能:
$('#close').click(function() {
var id = $(this).attr('id');
$('#full_image').animate({
height: 0
}, 300, function() {
$('#full_image img').attr('src','#');
});
$("#close_1").css({
display: "none"
});
$("#close_2").css({
display: "none"
});
$("#close").css({
display: "none"
});
});
【问题讨论】:
-
尝试 event.preventDefault() 悬停。 api.jquery.com/event.preventDefault
-
嗯,你会怎么把它写进去?
-
@Mihir 这不会阻止方法执行,也不会阻止指定的处理程序运行。它可以防止 default 操作,就像名称所暗示的那样,这不是所描述的问题。
-
好的,抱歉我误会了。您无法检测设备是否为触摸设备?如果是,则不要调用该函数。
标签: jquery click jquery-hover