我不知道到底该找什么,但这是我的问题。
<script>
function Gbox () {
var hide = document.getElementById('g-box').style.display = "none";
}
Gbox();
$("#g-plus").mouseover(function () {
$("#g-box").show(400);
});
$("#g-plus").mouseleave(function () {
$("#g-box").hide(400);
});
</script>说Jquery的工作没有问题。
唯一的问题是,如果我在#g-plus上快速地来回悬停2次,Jquery运行它的次数是show,hide,show,hide的4倍,当它发生时,它看起来很迟钝。
我怎样才能避免这个问题?
发布于 2015-05-19 13:32:49
您需要的是.stop()来停止先前的动画
function Gbox() {
$("#g-box").hide();
}
Gbox();
$("#g-plus").hover(function () {
$("#g-box").stop().show(400);
}, function () {
$("#g-box").stop().hide(400);
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button id="g-plus">g-plus</button>
<div id="g-box">g-box</div>
注意:您可以使用.hover()作为快捷方式注册mouseenter和mouseleave处理程序。
发布于 2015-05-19 13:29:31
$("#g-plus").hover(function () {
$("#g-box").show(400);
},function () {
$("#g-box").hide(400);
});https://stackoverflow.com/questions/30327046
复制相似问题