我有以下jQuery函数,但我不知道为什么在我放弃悬停后它会再次显示。概念是,如果类存在,在加载新菜单(从1.php)之后删除它们,等待1000并添加新类。它工作得很好,但是在我把鼠标移到其他地方之后,这个概念又运行了一遍。为什么?
$(document).ready(function () {
$("#cikkek").hover(function () {
$("div.navbar2").removeClass("visible");
$("div.logo-rotate").removeClass("logo-rotate2");
$("a.font-visibility").removeClass("font-visible");
$("div.block1").load("1.php");
setTimeout(function () {
$("div.navbar2").addClass("visible");
$("div.logo-rotate").addClass("logo-rotate2");
$("a.font-visibility").addClass("font-visible");
}, 1000);
});
});
发布于 2016-08-14 12:43:59
jQuery hover
绑定了两个事件,mouseenter
和mouseleave
,因此它将触发两次。
您可以使用空的mouseleave
函数,也可以不使用hover
,而是将其更改为mouseenter
$("div").mouseenter(function() {
$(this).css("background-color", "blue");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div>
Enter your mouse here
</div>
https://stackoverflow.com/questions/38942357
复制相似问题